I'm building a more or less simple encryption. Now after a bit of fuzzing and fiddling i came to a problem which i can't seem to find a solution for.
In the process of encryption i take a string as input and convert it to binary to do some math with it. After the "mathing" part im getting strings like this:
56010479313713691637235922367138913625577411202663921330215486595
now after this step i'm dissecting the string into pairs of 2 like this :
56 01 04 79 31 37 13 69 16 37 23 59 22 36 71 38 13 62 55 77 41 12 02 66 39 21 33 02 15 48 65 95
which is now still 1 string object. My problem is now that i can't seem to make up a method to actually take these pairs 1 by 1 to make some more math with them(afterwards i also want to probably convert the results into ascii or something else). Might just be the lack of sleep, but i can't seem to find a solution, any help would be appreciated :)
Edit : I now used the functions provided by timgeb to further process my code. Now im stuck at another rather stupid, let's call it bug.
Below is the code snippet that reads the encrypted string (which is numeric) from a file tmp.txt, comments explain the rest of it i guess. My problem is now that When i run the script it goes to the point where it joins back the int to a string but after that the replacing of the numeric pairs to letters does not work at all.
#***** Read from tmp.txt *****
alphaStr2 = linecache.getline('tmp.txt', 1)
alphaStr2 = int(alphaStr2) / 123456789
alphaStr = str(alphaStr2)
#***** Split into pairs of 2 *****
alphaStr = " ".join(alphaStr[i:i+2] for i in range(0, (len(alphaStr) + 1), 2))
#***** Convert to list *****
numStr = alphaStr.split()
#***** Convert list content to int's *****
numStr = map(int, numStr)
#***** simple math to adjust to alphabet lenght of 51 (Aa-Zz) *****
numMath = lambda x: x / 1.96078431372549
numStr = map(numMath, numStr)
#***** "round" float numbers to integer *****
numStr = [int(i) for i in numStr]
#***** convert back to string *****
numStr = ' '.join(str(x).zfill(2) for x in numStr)
#***** Convert numbers into letters *****
alphaStr = numStr.replace("00 ", "a")
alphaStr = numStr.replace("01 ", "b")
alphaStr = numStr.replace("02 ", "c")
alphaStr = numStr.replace("03 ", "d")
alphaStr = numStr.replace("04 ", "e")
.......