new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
24
Task/Caesar-cipher/JavaScript/caesar-cipher.js
Normal file
24
Task/Caesar-cipher/JavaScript/caesar-cipher.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<html><head><title>Caesar</title></head>
|
||||
<body><pre id='x'></pre>
|
||||
<script type="application/javascript">
|
||||
function disp(x) {
|
||||
var e = document.createTextNode(x + '\n');
|
||||
document.getElementById('x').appendChild(e);
|
||||
}
|
||||
|
||||
function trans(msg, rot) {
|
||||
return msg.replace(/([a-z])/ig,
|
||||
function($1) {
|
||||
var c = $1.charCodeAt(0);
|
||||
return String.fromCharCode(
|
||||
c >= 97 ? (c + rot + 26 - 97) % 26 + 97
|
||||
: (c + rot + 26 - 65) % 26 + 65);
|
||||
});
|
||||
}
|
||||
|
||||
var msg = "The quick brown f0x Jumped over the lazy Dog 123";
|
||||
var enc = trans(msg, 3);
|
||||
var dec = trans(enc, -3);
|
||||
|
||||
disp("Original:" + msg + "\nEncoded: " + enc + "\nDecoded: " + dec);
|
||||
</script></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue