diff options
author | William Carroll <wpcarro@gmail.com> | 2021-12-29T16·11-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2021-12-29T19·34+0000 |
commit | 4cf86f2e53881e473d881072e55b21179e4dd593 (patch) | |
tree | 0ea98356ffbb3dfe2f4abbd44317b2a5c81d6ea0 /users/wpcarro/scratch/cryptopals/set1/c2.py | |
parent | 5c0ec720afc83761d1afda44e9b6acd30375d898 (diff) |
feat(wpcarro/scratch): Upload my solutions to cryptopals r/3501
More beginner problems/solutions for CTF-style challenges. Change-Id: Ide229e99e3ccc1ede5a5ca1c2ad039498e49ea4c Reviewed-on: https://cl.tvl.fyi/c/depot/+/4740 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/scratch/cryptopals/set1/c2.py')
-rw-r--r-- | users/wpcarro/scratch/cryptopals/set1/c2.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/cryptopals/set1/c2.py b/users/wpcarro/scratch/cryptopals/set1/c2.py new file mode 100644 index 000000000000..badd60503d90 --- /dev/null +++ b/users/wpcarro/scratch/cryptopals/set1/c2.py @@ -0,0 +1,20 @@ +def fixed_xor(x, y, decode_hex=True, encode_hex=True): + if decode_hex: + x = bytearray.fromhex(x) + y = bytearray.fromhex(y) + + result = bytearray(len(x)) + + for i in range(len(x)): + result[i] = x[i] ^ y[i] + + return result.hex() if encode_hex else result + +run_tests = False +if run_tests: + actual = fixed_xor("1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965") + expect = "746865206b696420646f6e277420706c6179" + + print(actual) + assert actual == expect + print("Success!") |