#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    [Evalutation and Question]Problem with my program.


    Before i say something i want you to know that my english isn't perfect. I looked for help on polish forums, but in the end no one cared enough to help me.

    Few days ago my programing teacher in school gave me a homework. My job was to make a program that can encipher text, but in order to get the highest grade it cant be something simple like a ceaser shift or Visionere(im pretty sure i spelled it wrong).

    I didn't know much about cryptology so I watched some videos about enigma, and created a program that works like it. Actually it doesn't at all, all these two have in common are 3 rotors, and thats it. But i have encountered few problems with it. But before i talk about it I will try to explain how it works. Once again i remind you that my english is not perfect.


    So what happens first is you have to set 3 rotors, each rotor have 27 positions(0-26), and each position has assaigned a value (1-27), every value is unique, and there is no 2 positions with the same value assigned.

    After you set 3 rotors, you have to remember their positions, beacuse you will need them to decipher the message.

    Lets say you set rotors to (0 0 0) and want to encipher the word (abcde). What will happen first is that each letter will become a number (a=1 b=2 c=3 etc).

    All values from rotors will be added together, values for rotors set on (0 0 0) look, like this (10 3 1). These will be added together so, 10+3+1=14. And this will be added to the first letter that was turned into number so. 1 + 14 = 15. Now 15 will turn into a letter (1=a 2=b etc.).

    But before B is enciphered the first rotor will go from 0 to 1. so the rotors will be set like this (1 0 0) and the values will look like so (3 3 1). And the letter is going to be enciphered the same way buy instead of adding 14 to the letter it will add 7.

    When the rotors get to (26 0 0) next they will go to (0 1 0) and then (1 1 0) (2 1 0) etc.

    Deciphering works the same way but instead of adding the values it subtracts them.

    I'm sure this explanation looks to you like written by 8 years old kid, but
    "i cant english very well" if you speak polish i can explain it much better.

    Few aditional information:
    -It can encipher 26 letters and space.
    -Letter after enciphering can become itself
    -Letter after enciphering can become a space
    -Space after enciphering can become a space, and a letter.
    -All other symbols are treated like spaces, and they will be deciphered into spaces.

    So it pretty much works like Visioner and ceaser shift, but thanks to rotors program can encipher 19 683 letters uniqly.
    But the problem is... it doesn't. My teacher didn't notice it and i got the highest grade but its still bugging me. I checked the code many times, and every time, every part of the code worked fine, but still it doesn't encipher text they way i want.

    Now i will explain what the problem is.
    Lets try to encipher letter "a" 4000 times with the rotors set on
    (0 0 0). The result looks like this.
    ohlmrusfy jwpagdctbvzxinkqpzswxbecqikug lrondmfjhtyvakunrsx yldfpbvgmjizhaecotqwhrkopuxviacmzsdjgfweyb lqntnxquv caogiseyjpmlbkdhfrwtztcw afigumoykdpvsrhqjnlxbzerauyzdgeskmwibntqpfohljv xcjtmqrwzxkceoauflihyg dbnspvveybchkiwoq mfrxutjslpnzdaggqjnotwuh blyrcifevdxazkpmszibfglom sudqjvayxnwptrchekxg dejmkyqsbohtzwvlunrpafciakdhinqobuwfslxc zpyrvtejgm jcghmpnatverkwbzyoxqusdiflwfzcdiljxprangsyvuktmqo ebhmwptuzb nfhrdxiolkajcgeqvsyyhaefknlzrtcpiu xwmvosqbgdjudxabgjhvnpzleqwtsirkomyc fq txycfdrjlvhamspoengkiuzwbsbvz ehftlnxjcourqgpimkwaydcmfjkpsqdwyhunzebar txvglioislpqvywjbdn tekhgxfzcamroulvostyazmegqcwhnkj ibfdpurxdngklqtrexzivo fcbsauywhmjpfpimnsvtgzakxqbheducw yjolroyrvwadbphjtfzkqnmcleigsxu bleijorpcvxgtmyda qzswufkhntcw afigumoykdpvsrhqjnlxbzedngklqtrexzivo fcbsauywhmjpzibfglom sudqjvayxnwptrchekwfzcdiljxprangsyvuktmqo ebhbleijorpcvxgtmyda qzswufkhnhrkopuxviacmzsdjgfweyb lqntfpimnsvtgzakxqbheducw yjolryhaefknlzrtcpiu xwmvosqbgdjjtmqrwzxkceoauflihyg dbnspvveybchkiwoq mfrxutjslpnzdagnxquv caogiseyjpmlbkdhfrwtzlvostyazmegqcwhnkj ibfdpurxpzswxbecqikug lrondmfjhtyvaoyrvwadbphjtfzkqnmcleigsxu kunrsx yldfpbvgmjizhaecotqwakdhinqobuwfslxc zpyrvtejgmmwptuzb nfhrdxiolkajcgeqvsyislpqvywjbdn tekhgxfzcamroueohlmrusfy jwpagdctbvzxinkqgqjnotwuh blyrcifevdxazkpmsrauyzdgeskmwibntqpfohljv xcxg dejmkyqsbohtzwvlunrpafci jcghmpnatverkwbzyoxqusdiflsbvz ehftlnxjcourqgpimkwaydudxabgjhvnpzleqwtsirkomyc fcmfjkpsqdwyhunzebar txvglioq txycfdrjlvhamspoengkiuzwblvostyazmegqcwhnkj ibfdpurxwfzcdiljxprangsyvuktmqo ebhrauyzdgeskmwibntqpfohljv xcoyrvwadbphjtfzkqnmcleigsxu udxabgjhvnpzleqwtsirkomyc f jcghmpnatverkwbzyoxqusdiflyhaefknlzrtcpiu xwmvosqbgdjq txycfdrjlvhamspoengkiuzwbbleijorpcvxgtmyda qzswufkhnnxquv caogiseyjpmlbkdhfrwtzfpimnsvtgzakxqbheducw yjolrdngklqtrexzivo fcbsauywhmjphrkopuxviacmzsdjgfweyb lqntgqjnotwuh blyrcifevdxazkpmscmfjkpsqdwyhunzebar txvgliotcw afigumoykdpvsrhqjnlxbzeeohlmrusfy jwpagdctbvzxinkqakdhinqobuwfslxc zpyrvtejgmxg dejmkyqsbohtzwvlunrpafcizibfglom sudqjvayxnwptrchekjtmqrwzxkceoauflihyg dbnspvpzswxbecqikug lrondmfjhtyvasbvz ehftlnxjcourqgpimkwaydkunrsx yldfpbvgmjizhaecotqwmwptuzb nfhrdxiolkajcgeqvsyveybchkiwoq mfrxutjslpnzdagislpqvywjbdn tekhgxfzcamroufpimnsvtgzakxqbheducw yjolrq txycfdrjlvhamspoengkiuzwblvostyazmegqcwhnkj ibfdpurxislpqvywjbdn tekhgxfzcamrouoyrvwadbphjtfzkqnmcleigsxu udxabgjhvnpzleqwtsirkomyc fsbvz ehftlnxjcourqgpimkwaydkunrsx yldfpbvgmjizhaecotqwwfzcdiljxprangsyvuktmqo ebhhrkopuxviacmzsdjgfweyb lqnt jcghmpnatverkwbzyoxqusdiflyhaefknlzrtcpiu xwmvosqbgdjbleijorpcvxgtmyda qzswufkhnakdhinqobuwfslxc zpyrvtejgmxg dejmkyqsbohtzwvlunrpafcinxquv caogiseyjpmlbkdhfrwtzzibfglom sudqjvayxnwptrchekveybchkiwoq mfrxutjslpnzdagrauyzdgeskmwibntqpfohljv xctcw afigumoykdpvsrhqjnlxbzedngklqtrexzivo fcbsauywhmjpjtmqrwzxkceoauflihyg dbnspvmwptuzb nfhrdxiolkajcgeqvsyeohlmrusfy jwpagdctbvzxinkqgqjnotwuh blyrcifevdxazkpmspzswxbecqikug lrondmfjhtyvacmfjkpsqdwyhunzebar txvgliosbvz ehftlnxjcourqgpimkwaydcmfjkpsqdwyhunzebar txvglioyhaefknlzrtcpiu xwmvosqbgdjveybchkiwoq mfrxutjslpnzdagakdhinqobuwfslxc zpyrvtejgmgqjnotwuh blyrcifevdxazkpmseohlmrusfy jwpagdctbvzxinkqxg dejmkyqsbohtzwvlunrpafciislpqvywjbdn tekhgxfzcamrouudxabgjhvnpzleqwtsirkomyc fmwptuzb nfhrdxiolkajcgeqvsykunrsx yldfpbvgmjizhaecotqwoyrvwadbphjtfzkqnmcleigsxu nxquv caogiseyjpmlbkdhfrwtzjtmqrwzxkceoauflihyg dbnspv jcghmpnatverkwbzyoxqusdifllvostyazmegqcwhnkj ibfdpurxhrkopuxviacmzsdjgfweyb lqntdngklqtrexzivo fcbsauywhmjpfpimnsvtgzakxqbheducw yjolrq txycfdrjlvhamspoengkiuzwbwfzcdiljxprangsyvuktmqo ebhzibfglom sudqjvayxnwptrchekrauyzdgeskmwibntqpfohljv xctcw afigumoykdpvsrhqjnlxbzebleijorpcvxgtmyda qzswufkhnpzswxbecqikug lrondmfjhtyvaq txycfdrjlvhamspoengkiuzwbakdhinqobuwfslxc zpyrvtejgmwfzcdiljxprangsyvuktmqo ebhtcw afigumoykdpvsrhqjnlxbzezibfglom sudqjvayxnwptrchekeohlmrusfy jwpagdctbvzxinkqcmfjkpsqdwyhunzebar txvglioveybchkiwoq mfrxutjslpnzdaggqjnotwuh blyrcifevdxazkpmssbvz ehftlnxjcourqgpimkwaydkunrsx yldfpbvgmjizhaecotqwislpqvywjbdn tekhgxfzcamroumwptuzb nfhrdxiolkajcgeqvsylvostx
    Well, it looks like someone tried to type something with their forehead. At first, it looks perfect. 4000 letters a, was enciphered into something completly different and it doesn't look like the cipher is repeating. The problem is, the whole cypher is not repeating but parts of it are. It doesnt make any sense to me. Copy it to notepad and search for "ohlmrusfy" (first 9 letters) They repeat like 8 times, but surrounded by different letters and in random intervals. Same thing goes to other parts of the cipher. I'm clueless. Once again, my code is fine. My math seem to be wrong, but i dont know where im wrong.

    I tried to add more rotors but it only makes the repetition to appear even more frequently. I would love to give you my code and program, but they are in polish.

    And also, im just curious, how good is my program, how hard it would be to break?

    Also, i cant speak very well in english but i understund everything. So feel free to write complicated explanations.

    @edit
    I found this forum simply by searching "Cryptology forum", but now after reading few other threads in here I feel like this may not be the best place to to post this thread. You guys seem to be discussing stuff that is way more advanced than this. But please if you have some spare time, help me with this problem.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    As a simpler example, consider a set of rotors for encrypting 0-9; For example:
    Code:
    Rotor A = 1 2 3 4 5 6 7 8 9 0
    Rotor B = 2 4 6 8 0 1 3 5 7 9
    Rotor C = 0 9 8 7 6 5 4 3 2 1
    For the first ten input characters, the rotors will result in the following transformation:

    Code:
    (0 0 0) = +1 +2 +0 = +3
    (1 0 0) = +2 +2 +0 = +4
    (2 0 0) = +3 +2 +0 = +5
    (3 0 0) = +4 +2 +0 = +6
    (4 0 0) = +5 +2 +0 = +7
    (5 0 0) = +6 +2 +0 = +8
    (6 0 0) = +7 +2 +0 = +9
    (7 0 0) = +8 +2 +0 = +0
    (8 0 0) = +9 +2 +0 = +1
    (9 0 0) = +0 +2 +0 = +2
    A hundred and some cycles later, the rotors will come around to (0 6 1) which will produce a transformation identical to the first ten cycles:

    Code:
    (0 6 1) = +1 +3 +9 = +3
    (1 6 1) = +2 +3 +9 = +4
    (2 6 1) = +3 +3 +9 = +5
    (3 6 1) = +4 +3 +9 = +6
    (4 6 1) = +5 +3 +9 = +7
    (5 6 1) = +6 +3 +9 = +8
    (6 6 1) = +7 +3 +9 = +9
    (7 6 1) = +8 +3 +9 = +0
    (8 6 1) = +9 +3 +9 = +1
    (9 6 1) = +0 +3 +9 = +2
    And this same pattern will appear every time the second and third rotors result in +2.

    Comments on this post

    • satisek agrees : Great post, TY you helped me a lot
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    I cant belive you figured it out without even looking at the code.
    It seems so obvious right now, I cant belive i didn't figured this out myself. You're like a god of math to me right now. Thank you very much.

    But, how can i fix it? Now i know why adding more rotors was a bad idea, most of the time they stay at the same position.
    I have few other ideas, like making the rotors change their position more frequently, or making the filter that would detect when this situtation occurs, it would fix the problem of "random" repetition but in the end it would make the whole cipher to repeat more frequently.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    This is a bit out of my field, so the following may be a bit inaccurate.

    I think the problem you have is that although your rotors have 27**3 possible states, they can only produce 27 possible transformations (caesar ciphers with shifts of 0..26). Additionally, each rotor has the potential to reverse the cipher performed by the previous.

    Again this is out of my expertise so I can't say how secure this would be in practice (hopefully someone with more cryptoanalysis knowledge will comment) but you could produce better-looking results by increasing the number of possible transformations.

    For example, if the algorithm and middle rotor was changed as follows:

    Code:
    B-ENCRYPT =  1  2  4  5  7  8 10 11 13 14 16 17 19 20 22 23 25 26
    B-DECRYPT =  1 14  7 11  4 17 19  5 25  2 22  8 10 23 16 20 13 26
    
    Encrypt(x) = ((x + A[i]) * B-ENCRYPT[j]) + C[k]
    Decrypt(x) = ((x - C[k]) * B-DECRYPT[j]) - A[i]
    Since the B-rotor is now performing an other-than-caesar-cipher transformation, no setting on the C-rotor can reverse its effect.

    (Aside; If you're interested in why those particular values for B-ENCRYPT and B-DECRYPT work, you might find abstract algebra interesting. Specifically, the modular (or Euclidean) inverse, group theory (especially cyclic groups) and Lagrange's Theorm. It's interesting stuff and accessible with just an algebra background.)
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    I dont' really undestund what you mean. I'm beginner when it comes to algorithms and coding. Seriously, i'm still having problems with using functions, I mean i can use them but i'm still having problems with "Thinking with functions". This program was a real challenge for me, the only reason i doesn't work just like enigma is because i didn't know how to code it.

    Anyway, i have an idea for a different way to encipher the text but its impossible to decipher it by substracting the values, so i would have to use something like a reflector that enigma had. But then the cipher would had the same flaw that enigma had, letter could never become itself.

    @edit.
    I figured out how to write program that emulates enigma. So
    I'll write program with 6 rotors. First 3 will work the same way as enigma.
    Input -> 1st rotor -> 2nd rotor -> 3rd rotor -> reflector -> 3rd rotor -> 2nd rotor -> 1st rotor -> output

    At this point because of the reflector the letter after encryption can never become itself. This is a serious flaw that allowed code breakers break enigma during War World II.

    After the text is enciphered with first 3 rotors, it will go to the next 3, however these rotors will do the same transformation as the one i described in the first post.

    I thought about my 1st design and i came to the conclusion that this way of encryption is weak and very vulnerable to brute force. However combined with the 3 enigma rotors, it will allow letter to become itself, and in the end it will add 3 additional rotors, which will strenghten the cipher.
    So there are going to be 387 420 489 possible settings of the rotors, and the cipher should no longer "randomly" repeat itself. I dont know how fast good pc can check this number of combinations but im sure this is still vulnerable to brute force, but i have other clever idea how to fix it, but i dont really know how to code it, but i'm sure i'll figure it out.

IMN logo majestic logo threadwatch logo seochat tools logo