Last active
April 26, 2021 05:43
-
-
Save dhrumilp15/874a14d64a732f754fb7721a46fee466 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
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