-1

So I have a bit of text that I have to pass into a playfair cipher to be encrypted. The issue is I want to preserve the punctuation that is used in the string. For example "Timmy, What's your favorite color?" might be the string I want to encrypt. I need a way that whenever the text is encrypted it removes the punctuation and then adds it back into the output so for the above example I might get "chds, xgdd'a ywte gdfabyqt olshf?". I also need to be able to do the same when the message is then decoded. Any help is appreiated!

PS: Don't need any help with the key portion. Just the PT to CT punctuation preservation.

Jacob Reed
  • 37
  • 7

2 Answers2

0

You could create a char[] with a size equal to the original String and pre-seed it with the punctation from that String at the index it is found. Then when you get the encrypted/decrypted String, just loop through each character in the new String and place them in the char[] skipping over the ones already filled by punctuation. Then create a String from the char[].

D. Law.
  • 234
  • 1
  • 3
  • 8
0

it appears to me that you only want to encrypt the 'pure text' leaving all non-alpha numeric char sets. If that is the case, then you can create your own data structure something like :

class StringElement{
   String contentToEncrypt;
   Boolean shouldEncrypt;
  }

you can convert your string into a list/hash/array. While doing so, you will have to split the string into its components and decide if the component should be ciphered or not e.g. Timmy, What's your favorite color?, may become {["Timmy", true], [",", false]...} to encrypt "Timmy", but to leave "," out from encryption.

DevdattaK
  • 198
  • 9