Base64 encode

Iniciado por Dedalo, Septiembre 13, 2014, 11:25:15 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Bueno, hace tiempo no compartía algo aquí pero pienso que compartir este código los puede ayudar. Todos hemos usado alguna vez base64 encode pero ¿qué hay detrás de la función?...

Código: python
#!/usr/bin/python

def base64encode(encode):
s = encode
keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
out = ""
nums = 0
i = 0
while (i<len(s)):
if nums == 6:
out += keys[ord(s[i - 1]) & 63]
out += keys[ord(s[i]) >> 2]
nums = 2
else:
chr1 = ord(s[i - 1]) & (2 ** nums - 1)
chr2 = ord(s[i]) >> (nums + 2)
chrt = (chr1 << (6 - nums)) | chr2
out += keys[chrt]
nums += 2
i = i + 1
if nums != 0:
out += keys[(ord(s[len(s) - 1]) & (2 ** nums - 1)) << (6 - nums)]

return out

print base64encode("Base64 This")



You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Saludos,
Dedalo.
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Muy bueno bro, primer vez que veo un Base64 usando operaciones binarias.

Saludos!







You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Muy bueno! +1
Pentest - Hacking & Security Services

Contact me: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login