1
0
This commit is contained in:
2023-09-29 23:48:37 +08:00
parent 450afba784
commit 5dc0686317
14 changed files with 1301 additions and 5 deletions

20
set1/challenge5.py Normal file
View File

@@ -0,0 +1,20 @@
def repeating_key_xor(key, message):
key_length = len(key)
message_length = len(message)
expanded_key = (key * (int(message_length / key_length))) + key[:message_length % key_length]
return bytes([m ^ k for m, k in zip(message, expanded_key)])
message = "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal"
key = "ICE"
# Convert message and key to bytes
message = message.encode('utf-8')
key = key.encode('utf-8')
cipher = repeating_key_xor(key, message)
# Convert to hexadecimal
cipher_hex = cipher.hex()
print(cipher_hex)