commit 106d61dcbc330a71812babd9e851a82b3d5cd088 Author: Josiah Ledbetter Date: Fri Sep 7 19:37:07 2018 -0500 Initial commit. Get stuff on github. diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..988937c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/usr/local/bin/python3" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..916f017 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +a place to hold my cryptopals attempts and terrible code. diff --git a/challenge1.py b/challenge1.py new file mode 100644 index 0000000..a789f48 --- /dev/null +++ b/challenge1.py @@ -0,0 +1,6 @@ +from binascii import unhexlify, b2a_base64 + +# Use the binascii.unhexlify() function to convert from a hex string to bytes. Then use the binascii.b2a_base64() function to convert that to Base64: + +result = b2a_base64(unhexlify("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d")) +print(result) \ No newline at end of file diff --git a/challenge2.py b/challenge2.py new file mode 100644 index 0000000..977fadd --- /dev/null +++ b/challenge2.py @@ -0,0 +1,62 @@ +from binascii import unhexlify + +# see what each value is unhexlified: +test = bytearray.fromhex("1c0111001f010100061a024b53535009181c").decode() +test2 = bytearray.fromhex("686974207468652062756c6c277320657965").decode() +print(test) +print(test2) + +# if converting from strings, you must convert characters to integers and XOR those instead, and then...unconvert them? +# example with XORing integers +input1 = 12345 +input2 = 67890 +xored1 = input1 ^ input2 +print(xored1) + +# now prove that worked + +print(input1 ^ xored1) # should be = to input2 + +# now i need to convert strings to integers +text = "suck myass BITCH" +numArray = [] +for letter in text: + number = ord(letter) + numArray.append(number) + +print(numArray) + +# ok now convert that array of ints back to strings +letterArray = [] +for number in numArray: + letter = chr(number) + letterArray.append(letter) + +print(letterArray) + +# OK DOPE now turn it into a function + +def xor_TwoEqualLengthBuffers(arg1, arg2): + arg1value = bytearray.fromhex(arg1).decode() + arg2value = bytearray.fromhex(arg2).decode() + + numArray1 = [] + for letter in arg1value: + number1 = ord(letter) + numArray1.append(number1) + + int1 = int(''.join(str(i) for i in numArray1)) + + + numArray2 = [] + for letter in arg2value: + number2 = ord(letter) + numArray2.append(number2) + + int2 = int(''.join(str(i) for i in numArray2)) + + + xoredValue = int1 ^ int2 + + +xor_TwoEqualLengthBuffers("1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965") \ No newline at end of file