ISCL Lab3
Jump to navigation
Jump to search
Perform encryption and Decryption of Caesar cipher. Write a script for performing these operations
<html> <head> <script> function encrypt(text, s) { let result=""; for (let i = 0; i < text.length; i++) { let char = text[i]; let ch = String.fromCharCode(char.charCodeAt() + s); result += ch; } return result; } function dencrypt(text, s) { let result="" for (let i = 0; i < text.length; i++) { let char = text[i]; let ch = String.fromCharCode(char.charCodeAt() -s); result += ch; } return result; } // Driver code let text = "HORRIBLE"; let s = 4; document.write("Text : " + text + "<br>"); document.write("Shift : " + s + "<br>"); document.write("Cipher: " + encrypt(text, s) + "<br>"); let text1 = encrypt(text, s); document.write("Text1 : " + text1 + "<br>"); document.write("Shift : " + s + "<br>"); document.write("Cipher: " + dencrypt(text1, s) + "<br>"); </script> </head> </html>