Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. var cipherResult = document.getElementById('cipherResult');
  2. var descramblerResult = document.getElementById('descramblerResult');
  3.  
  4.  
  5. function rot4(str)
  6. {
  7. var first = document.getElementById('first').value;
  8. var str = first;
  9. console.log(str);
  10.  
  11. var num = document.getElementById('number').value;
  12. var ilee = parseInt(num,10);
  13. zdanie = "";
  14.  
  15. for (var i = 0; i < str.length ; i++)
  16. {
  17. console.log(ilee);
  18. //var zmienna = prompt("Wprowadz tutaj wartosc");
  19.  
  20. var asciinum = str[i].charCodeAt();// Zamienia podana litere na liczbe z ASCII
  21. if(asciinum==32)
  22. {
  23. zdanie +=String.fromCharCode(asciinum);
  24. }
  25. else if ( (asciinum + ilee >= 97 && asciinum + ilee <= 122) || (asciinum + ilee >= 65 && asciinum + ilee <= 90))
  26. {
  27. zdanie += String.fromCharCode(asciinum + ilee); // zmienna letter przeksztalca z liczby ASCII na litere + dodaje 4
  28. }
  29. else
  30. {
  31. zdanie += String.fromCharCode(asciinum + ilee -26);
  32. }
  33.  
  34. }
  35. return cipherResult.textContent = zdanie;
  36. };
  37.  
  38. function odrot4(str)
  39. {
  40. str = this.zdanie;
  41. var num = document.getElementById('number').value;
  42. var ile = parseInt(num,10);
  43. ile = ile*(-1);
  44. var zdanie = "";
  45.  
  46. for (var i = 0; i < str.length ; i++)
  47. {
  48. //var zmienna = prompt("Wprowadz tutaj wartosc");
  49.  
  50. var asciinum = str[i].charCodeAt();// Zamienia podana litere na liczbe z ASCII
  51. if(asciinum==32)
  52. {
  53. zdanie +=String.fromCharCode(asciinum);
  54. }
  55. else if ( (asciinum + ile >= 97 && asciinum + ile <= 122) || (asciinum + ile >= 65 && asciinum + ile <= 90))
  56. {
  57. zdanie += String.fromCharCode(asciinum + ile); // zmienna letter przeksztalca z liczby ASCII na litere + dodaje 4
  58. }
  59. else
  60. {
  61. zdanie += String.fromCharCode(asciinum + ile +26);
  62. }
  63.  
  64. }
  65. return descramblerResult.textContent = zdanie;
  66. };
  67.  
  68. // var currentLetter = "e";
  69.  
  70.  
  71. // var asciiCode = currentLetter.charCodeAt();
  72. // var plus4 = asciiCode + 4;
  73.  
  74. // var convertedLetter = String.fromCharCode(plus4);
  75.  
  76. // console.log(asciiCode);
  77. // console.log(plus4);
  78. // console.log(convertedLetter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement