in my python program i generate a list of numbers which looks like this:
gen1=(random.sample(range(33,126), 8))
conv=(gen1[0:])
then that list is converted to chr like this:
chr="".join([chr(i) for i in conv])
the printed result for example would look like this:
`&+hs,DY
Now my question is, how do i convert it back to how it was in 'conv' later on in my program, the user enters the generated key and my program need to reverse engineer it back to calculate something, i tried this:
InPut=input("Please enter the key you used to encrypt the above text: ")
ord_key="".join([ord for d in InPut])
but that doesnt work if there is numbers in the key that was generated earlier please help me
You are not calling ord
properly, this should do:
InPut=input("Please enter the key you used to encrypt the above text: ")
ord_key="".join(map(str,[ord(d) for d in InPut]))
if you want to reverse the stringfied '&+hs,DY
just map
chr to it:
reversed = map(chr, "`&+hs,DY")
If you are using python 3.x transform it to a list:
reversed = list(map(chr, "`&+hs,DY"))