Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Caesar-cipher/Jsish/caesar-cipher.jsish
Normal file
33
Task/Caesar-cipher/Jsish/caesar-cipher.jsish
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* Caesar cipher, in Jsish */
|
||||
"use strict";
|
||||
|
||||
function caesarCipher(input:string, key:number):string {
|
||||
return input.replace(/([a-z])/g,
|
||||
function(mat, p1, ofs, str) {
|
||||
return Util.fromCharCode((p1.charCodeAt(0) + key + 26 - 97) % 26 + 97);
|
||||
}).replace(/([A-Z])/g,
|
||||
function(mat, p1, ofs, str) {
|
||||
return Util.fromCharCode((p1.charCodeAt(0) + key + 26 - 65) % 26 + 65);
|
||||
});
|
||||
}
|
||||
|
||||
provide('caesarCipher', 1);
|
||||
|
||||
if (Interp.conf('unitTest')) {
|
||||
var str = 'The five boxing wizards jump quickly';
|
||||
; str;
|
||||
; 'Enciphered:';
|
||||
; caesarCipher(str, 3);
|
||||
; 'Enciphered then deciphered';
|
||||
; caesarCipher(caesarCipher(str, 3), -3);
|
||||
}
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
str ==> The five boxing wizards jump quickly
|
||||
'Enciphered:'
|
||||
caesarCipher(str, 3) ==> Wkh ilyh eralqj zlcdugv mxps txlfnob
|
||||
'Enciphered then deciphered'
|
||||
caesarCipher(caesarCipher(str, 3), -3) ==> The five boxing wizards jump quickly
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue