Simple Shift Cipher
Paste the block of text that you want to work on into the "Plaintext" box.
- R moves the cipher text 1 letter to the right. A plaintext = Z ciphertext. This is equivalent to subtracting 1 from the value of the plaintext letter. P-1=C
- L moves the cipher text 1 letter to the left. A plaintext = B ciphertext. P+1=C
The results appear in the "Manipulated Text" box.
If you can read JavaScript then download the source and fiddle with it! The code has plenty of comments on it.
Notes on the JavaScript code.
//Get the current shift value
alp = eval(document.form1.alpShift.value);
- document tells the machine to look at what it has written to the screen.
- form1 is the part of the document to look at. This is where the text boxes have to be.
- alpShift is the name of the textbox we want.
- .value get the value of the textbox we want. This will be interpreted as a String..
- eval converts a String into a numerical value.
//Get the ascii code of the current letter.
var letterCode =text.charCodeAt(c) ;
- text.charCodeAt(c) counting from 0 go to the c-th letter of string text and return the value of its ascii code
- var this means that lettercode is a local variable. What we do to it only works within this function.
//See notes on main page
blurb = blurb + String.fromCharCode(65+(letterCode-65-alp+26*10)%26); }
- (65+(letterCode-65-alp+26*10)%26)lettercode is a number between 65 and 90.
- Take 65 away so that A now corresponds to 0.
- Take away the current value of the code shift to undo the effect of the encipherment.
- Add 260 to make sure that the value is positive and then find the remainder on division by 26 %26
- String.fromCharCode(65+This adds 65 back to put our number in the range of ascii codes for A-Z before converting it back into a letter.
ASCII codes
These are the decimal numbers used by the machine to store letters and other characters.
- 32 space
- 65 A
- 90 Z
- 97 a
- 122 z
Useful References
w3schools.com JavaScript reference resources.
Wiki table of ASCII codes.