Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="cezar">
- informacja: <input type="text"><br>
- przesuniecie: <input type="number"><br>
- <input type="button" value="szyfruj" id="s" onclick="c(this)"><input type="button" id="ds" value="deszyfruj" onclick="c(this)">
- </form>
- <p id="cw"></p>
- <form id="asym">
- informacja: <input type="number"><br>
- klucz: <input type="number"><br>
- <input type="button" value="szyfruj" id="s" onclick="d(this)"><input type="button" id="ds" value="deszyfruj" onclick="d(this)">
- </form>
- <p id="sw"></p>
- <script>
- function cezar(info, p){
- info = info.toLowerCase()
- let out = "", tmp
- for(let i = 0; i<info.length; i++){
- tmp = info[i].charCodeAt()+parseInt(p)
- console.log(tmp)
- if(tmp>122){
- tmp = tmp-26
- } else if(tmp<97){
- tmp = tmp+26
- }
- out += String.fromCharCode(tmp)
- }
- return out
- }
- function c(b){
- let a = document.getElementById("cezar").children
- let info = a[0].value, p = a[2].value, cw = document.getElementById("cw")
- if (b.id == "s"){
- cw.innerHTML = cezar(info, p)
- } else if (b.id == "ds"){
- cw.innerHTML = cezar(info, p*-1)
- }
- }
- function d(b){
- let a = document.getElementById("asym").children
- let info = a[0].value, p = a[2].value, sw = document.getElementById("sw")
- if (b.id == "s"){
- sw.innerHTML = info*7*p //publiczny
- } else if (b.id == "ds"){
- sw.innerHTML = info/p //prywatny
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement