Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Caesar-cipher/TypeScript/caesar-cipher.ts
Normal file
14
Task/Caesar-cipher/TypeScript/caesar-cipher.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function replace(input: string, key: number) : string {
|
||||
return input.replace(/([a-z])/g,
|
||||
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 97) % 26 + 97)
|
||||
).replace(/([A-Z])/g,
|
||||
($1) => String.fromCharCode(($1.charCodeAt(0) + key + 26 - 65) % 26 + 65));
|
||||
}
|
||||
|
||||
// test
|
||||
var str = 'The five boxing wizards jump quickly';
|
||||
var encoded = replace(str, 3);
|
||||
var decoded = replace(encoded, -3);
|
||||
|
||||
console.log('Enciphered: ' + encoded);
|
||||
console.log('Deciphered: ' + decoded);
|
||||
Loading…
Add table
Add a link
Reference in a new issue