Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,11 @@
function caesar (text, shift) {
return text.toUpperCase().replace(/[^A-Z]/g,'').replace(/./g, function(a) {
return String.fromCharCode(65+(a.charCodeAt(0)-65+shift)%26);
});
}
// Tests
var text = 'veni, vidi, vici';
for (var i = 0; i<26; i++) {
console.log(i+': '+caesar(text,i));
}

View file

@ -0,0 +1,5 @@
var caesar = (text, shift) => text
.toUpperCase()
.replace(/[^A-Z]/g, '')
.replace(/./g, a =>
String.fromCharCode(65 + (a.charCodeAt(0) - 65 + shift) % 26));

View file

@ -0,0 +1,43 @@
((key, strPlain) => {
// Int -> String -> String
let caesar = (k, s) => s.split('')
.map(c => tr(
inRange(['a', 'z'], c) ? 'a' :
inRange(['A', 'Z'], c) ? 'A' : 0,
k, c
))
.join('');
// Int -> String -> String
let unCaesar = (k, s) => caesar(26 - (k % 26), s);
// Char -> Int -> Char -> Char
let tr = (base, offset, char) =>
base ? (
String.fromCharCode(
ord(base) + (
ord(char) - ord(base) + offset
) % 26
)
) : char;
// [a, a] -> a -> b
let inRange = ([min, max], v) => !(v < min || v > max);
// Char -> Int
let ord = c => c.charCodeAt(0);
// range :: Int -> Int -> [Int]
let range = (m, n) =>
Array.from({
length: Math.floor(n - m) + 1
}, (_, i) => m + i);
// TEST
let strCipher = caesar(key, strPlain),
strDecode = unCaesar(key, strCipher);
return [strCipher, ' -> ', strDecode];
})(114, 'Curio, Cesare venne, e vide e vinse ? ');