Skip to content

Instantly share code, notes, and snippets.

@dhrumilp15
Last active April 26, 2021 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhrumilp15/874a14d64a732f754fb7721a46fee466 to your computer and use it in GitHub Desktop.
Save dhrumilp15/874a14d64a732f754fb7721a46fee466 to your computer and use it in GitHub Desktop.
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