Created
March 12, 2012 20:39
-
-
Save badmofo/2024552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def password_hashes(password): | |
alpha = sum([c * (i + 1) % 9 for i,c in enumerate(password)]) | |
beta = (password[0] + password[-1] + len(password)) % 9 | |
if beta == 0: | |
beta = 20 | |
return alpha, beta | |
def reverse(seq): | |
return seq[::-1] | |
def decrypt(plaintext, password): | |
password = map(ord, password.strip()) | |
plaintext = map(ord, reverse(plaintext.strip()).decode('hex')) | |
alpha, beta = password_hashes(password) | |
gamma, plaintext = plaintext[0], plaintext[1:] | |
plaintext = [ | |
(c - beta - gamma - password[(alpha + gamma + i) % len(password)] + 254) % 254 | |
for i,c in enumerate(plaintext)] | |
return ''.join(map(chr, reverse(plaintext))) | |
def encrypt(plaintext, password): | |
plaintext = reverse(map(ord, plaintext.strip())) | |
password = map(ord, password.strip()) | |
alpha, beta = password_hashes(password) | |
k = sum([c * (i + 1) % 9 for i,c in enumerate(plaintext)]) | |
gamma = (alpha + k) % 143 | |
for i2 in range(len(plaintext)): | |
plaintext[i2] = (plaintext[i2] + beta + gamma + password[(alpha + gamma + i2) % len(password)] + 254) % 254 | |
return reverse((''.join(map(chr, [gamma] + plaintext))).encode('hex').upper()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment