Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BLOCK_LEN = 8
HEX_BLOCK_LEN = 16
def encrypt_block(plaintext):
'''Encrypts a given block of plaintext'''
k = open("./key").read().rstrip()
result = int(binascii.hexlify(plaintext), 16)
for i in range(ROUNDS):
# The round function is the below lines
key = int(binascii.hexlify(k[i * BLOCK_LEN:(i + 1) * BLOCK_LEN]), 16) # Grabs a block of the key
key_odd = key | 1 # Creates an odd version of the key
result ^= key # Xor's the result with the key
result = g(result) # Reverses the bits in result
result = (result * key_odd) % (1 << 64) # Multiplies the result with the odd-ed key, forces a 64-bit number
return hex(result).lstrip("0x").rstrip("L").rjust(HEX_BLOCK_LEN, "0") # Converts the result to a 16-character hex block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment