HEX to ASCII
markotaht at gmail.com
markotaht at gmail.com
Mon Oct 7 09:51:29 EDT 2013
esmaspäev, 7. oktoober 2013 4:27.44 UTC+3 kirjutas Piet van Oostrum:
> markotaht at gmail.com writes:
>
>
>
> > problem is : Traceback (most recent call last):
>
> > File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in <module>
>
> > print("Key-" + str(võti) + ": " + str("".join(tulemus2)))
>
> > TypeError: sequence item 0: expected str instance, bytes found
>
> >
>
> > If i take away the join command i get this:
>
> > Key-00000000: [b'u', b'o', b'\x00', b'\x1d', b' ', b'|', b'N', b'\x0f', b'9', b'j', b'K', b'J', b'&', b'#', b'A', b'K', b'5', b'k', b'_', b'\x1e', b',', b'j', b'\x0c', b'\x08', b'i', b'(', b'\x06', b'\\', b'r', b'3', b'\x1f', b'V', b's', b'9', b'\x1d']
>
> >
>
> > the Key-00000000 is the key im using to decrypt the code. everything else is generated by the decrytion process and the unhexlify command. So my guess is, the join command cant handle the b"u" type of format. how can i get rid of the b.
>
> >
>
> > Or does anyone have a better idea how to translate HEX into ASCII and sort out the lines that make sense
>
>
>
> Why do you post the same question twice under different subjects?
>
> --
Because i was told so, cause the subject change so it cant be under there anymore.
This is the code i came up with:
from teisendaja import *
from operator import *
import binascii
teisendus = teisendus()
kood = input("Kood: ")
key = input("Võti: ")
chunksize = 2
vastus = [teisendus.teisendus3(16,2,kood[i: (i + chunksize)]) for i in range(0, len(kood),chunksize)]
vastus = ["0"*(8-len(x)) + x for x in vastus]
#key = teisendus.teisendus3(10,2,int(key))
getBin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + str(bin(x))[3:].zfill(n)
def dekrüpteeria(vastus, key):
XOR = []
tulemus = []
for i in range(len(vastus)):
for j in range(8):
XOR.append(str(ixor(int(vastus[i][j]), int(key[j]))))
tulemus.append("".join(XOR))
key = "".join(XOR)
XOR = []
return tulemus
tulemus2= []
if key == "":
for i in range(256):
võti = getBin(i,8)
tulemus = [teisendus.teisendus3(2,16,i) for i in dekrüpteeria(vastus, võti)]
tulemus = ["0"*(2-len(x)) + x for x in tulemus]
# for j in range(len(tulemus)):
tulemus2.append(binascii.unhexlify("".join(tulemus)))
print("Key-" + str(võti) + ": " + str(tulemus2))
tulemus2 = []
#tulemus = [teisendus.teisendus3(2,16,i) for i in dekrüpteeria(vastus, key)]
#print(":".join(tulemus))
#751a6f1d3d5c3241365321016c05620a7e5e34413246660461412e5a2e412c49254a24
Although this is quite ugly atm. But it serves me well, until i reach the unhexlify part. The number and lette r string at the wery end is the mesage im trying to decypher.
More information about the Python-list
mailing list