|
| 1 | +SimpleCipher = require 'simple_cipher' |
| 2 | + |
| 3 | +describe 'simple-cipher', -> |
| 4 | + describe 'Random key cipher', -> |
| 5 | + it 'Can encode', -> |
| 6 | + cipher = SimpleCipher! |
| 7 | + plaintext = 'aaaaaaaaaa' |
| 8 | + encoded = cipher\encode plaintext |
| 9 | + expected = cipher\key!\sub(1, #plaintext) |
| 10 | + assert.are.equal expected, encoded |
| 11 | + |
| 12 | + pending 'Can decode', -> |
| 13 | + cipher = SimpleCipher! |
| 14 | + expected = 'aaaaaaaaaa' |
| 15 | + ciphertext = cipher\key!\sub(1, #expected) |
| 16 | + decoded = cipher\decode ciphertext |
| 17 | + assert.are.equal expected, decoded |
| 18 | + |
| 19 | + pending 'Is reversible. I.e., if you apply decode in a encoded result, you must see the same plaintext encode parameter as a result of the decode method', -> |
| 20 | + cipher = SimpleCipher! |
| 21 | + plaintext = 'abcdefghij' |
| 22 | + ciphertext = cipher\encode plaintext |
| 23 | + decoded = cipher\decode ciphertext |
| 24 | + assert.are.equal plaintext, decoded |
| 25 | + |
| 26 | + pending 'Key is made only of lowercase letters', -> |
| 27 | + cipher = SimpleCipher! |
| 28 | + key = cipher\key! |
| 29 | + assert.is.truthy key\match('^[a-z]+$') |
| 30 | + |
| 31 | + describe 'Substitution cipher', -> |
| 32 | + pending 'Can encode', -> |
| 33 | + cipher = SimpleCipher 'abcdefghij' |
| 34 | + result = cipher\encode 'aaaaaaaaaa' |
| 35 | + assert.are.equal 'abcdefghij', result |
| 36 | + |
| 37 | + pending 'Can decode', -> |
| 38 | + cipher = SimpleCipher 'abcdefghij' |
| 39 | + result = cipher\decode 'abcdefghij' |
| 40 | + assert.are.equal 'aaaaaaaaaa', result |
| 41 | + |
| 42 | + pending 'Is reversible. I.e., if you apply decode in a encoded result, you must see the same plaintext encode parameter as a result of the decode method', -> |
| 43 | + cipher = SimpleCipher 'abcdefghij' |
| 44 | + ciphertext = cipher\encode 'abcdefghij' |
| 45 | + result = cipher\decode ciphertext |
| 46 | + assert.are.equal 'abcdefghij', result |
| 47 | + |
| 48 | + pending 'Can double shift encode', -> |
| 49 | + cipher = SimpleCipher 'iamapandabear' |
| 50 | + result = cipher\encode 'iamapandabear' |
| 51 | + assert.are.equal 'qayaeaagaciai', result |
| 52 | + |
| 53 | + pending 'Can wrap on encode', -> |
| 54 | + cipher = SimpleCipher 'abcdefghij' |
| 55 | + result = cipher\encode 'zzzzzzzzzz' |
| 56 | + assert.are.equal 'zabcdefghi', result |
| 57 | + |
| 58 | + pending 'Can wrap on decode', -> |
| 59 | + cipher = SimpleCipher 'abcdefghij' |
| 60 | + result = cipher\decode 'zabcdefghi' |
| 61 | + assert.are.equal 'zzzzzzzzzz', result |
| 62 | + |
| 63 | + pending 'Can encode messages longer than the key', -> |
| 64 | + cipher = SimpleCipher 'abc' |
| 65 | + result = cipher\encode 'iamapandabear' |
| 66 | + assert.are.equal 'iboaqcnecbfcr', result |
| 67 | + |
| 68 | + pending 'Can decode messages longer than the key', -> |
| 69 | + cipher = SimpleCipher 'abc' |
| 70 | + result = cipher\decode 'iboaqcnecbfcr' |
| 71 | + assert.are.equal 'iamapandabear', result |
0 commit comments