Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Caesar Cipher</title>
- <meta charset = "UTF-8">
- </head>
- <body>
- <script>
- CHARTABLE = [ 'a', 'b', 'c', 'č', 'd',
- 'e', 'f', 'g', 'h', 'i',
- 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'r', 's', 'š',
- 't', 'u', 'v', 'z', 'ž','_', 0];
- PLAIN_MESSAGE = ['p','r','e','m','i','k','_',
- 'v','s','e','h','_',
- 'e','n','o','t','_',
- 'i','z','_',
- 'b','r','e','t','a','n','i','j','e','_',
- 'v','_',
- 'g','a','l','i','j','o','_',
- 't','a','k','o','j','_',
- 'c','e','a','s','a','r',0];
- IMPORTANT_MESSAGE = [ 'v','n','p','b','m','e', 'g','n','u','l','m','e', 'f','b','p','u','k','z', 'b','h','e','g','n','u', 'l','k','z','b','č','j', 'e','h', 0];
- key = ['a', 'm', 'f', 'o', 'r', 'a', 0];
- keyLen = 6;
- function getCharIndex(c)
- {
- var i;
- for(i = 0; CHARTABLE[i] != 0; i++)
- {
- if(CHARTABLE[i] == c) return i;
- }
- return -1;
- }
- function encryptCharCaesar(c, n)
- {
- return CHARTABLE[(getCharIndex(c)+n)%26];
- }
- function decryptCharCaesar(c, n)
- {
- return CHARTABLE[(26*n + getCharIndex(c)-n)%26]
- }
- function encryptVigenere(msg)
- {
- enc = '';
- for(var i = 0, j = 0; msg[i] != 0; i++, j++)
- {
- enc += CHARTABLE[(getCharIndex(msg[i]) + getCharIndex(key[j % keyLen]))%26];
- }
- return enc;
- }
- DECRYPTED_MESSAGE = '';
- for(i = 0; IMPORTANT_MESSAGE[i] != 0; i++)
- {
- DECRYPTED_MESSAGE += decryptCharCaesar(IMPORTANT_MESSAGE[i], 22);
- }
- console.log(DECRYPTED_MESSAGE);
- MSG = ['p', 'r', 'i', 'm', 'i', 't', 'e', 'o', 'b', 'e', 'l', 'i', 'k', 's', 'a', 0];
- console.log(encryptVigenere(MSG));
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement