0

The program reads the file the user wants to encrypt:

with open(encryptSpecialFileName,mode= "r",encoding= "UTF-8") as myFile:
        fileToSpecialEncrypt = myFile.read().splitlines()

The program then sets up the list for the encrypted message.

    encryptedSpecialFile = []
    for string in fileToSpecialEncrypt:
        s1 = ""
        for char in string:

(Here it calls the function that encrypts the file)

encryptedSpecialChar = encryptSpecialCharacter(char, offset)

Then the encrypted characters are added to the list.

 s1 = s1 + encryptedSpecialChar      
 encryptedSpecialFile.append(s1) 

How would I split this string into chunks of five to make decryption more difficult?

timgeb
  • 76,762
  • 20
  • 123
  • 145
flocd
  • 31
  • 3
  • 1. Print characters 0 through 4. 2. Print characters 5 through 9. 3. Print characters 10 through 14. 4. Print characters 15 through 19. I'm sure you get the picture? – user253751 Jan 30 '16 at 12:39
  • 3
    Also, standard disclaimer: keep in mind that any encryption algorithms you come up with are probably easy to break, even if *you* can't break them. So don't use them for anything serious. – user253751 Jan 30 '16 at 12:39
  • Take a look at http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python – PM 2Ring Jan 30 '16 at 12:40
  • BTW, it's slightly more efficient to collect your strings into a list and then use the string `.join()` method to combine all the strings into one string. Also, `string` is not a good variable name since that's the name of a standard module. – PM 2Ring Jan 30 '16 at 12:44

1 Answers1

1

To split the encrypted string into groups of five, we may collect first 5 characters into a string and then append the string into a list. Then we repeat the process until the entire encrypted string is exhausted.

encryptedString = "Thisistheencryptedtexttobesplitintogroupsoffive."
encryptedChunks = []

chunk = ""
for ch in encryptedString:
    if len(chunk)==5:
        encryptedChunks.append(chunk)
        chunk = ch
    else:
        chunk += ch
encryptedChunks.append(chunk)

print encryptedChunks

Here, the variable encryptedString contains the string returned from your function encryptSpecialCharacter(char, offset).

Pratanu Mandal
  • 597
  • 8
  • 23