Advertisement
Guest User

Untitled

a guest
Feb 6th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3.  
  4. <head>
  5. <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  6. <meta charset="utf-8">
  7.  
  8. </head>
  9.  
  10. <body>
  11. <select>
  12. <option value = "crypt" selected>Крипт</option>
  13. <option value = "decrypt">Декрипт</option>
  14. </select>
  15. <textarea id="before" >Enter text here...</textarea>
  16. <button>click me</button>
  17. <script>
  18. var select = document.querySelector('select');
  19. var button = document.querySelector('button');
  20. var alf = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM .,";
  21.  
  22. button.addEventListener('click', function(){
  23. var text = $("#before").val();
  24. console.log(text);
  25. if (select.value=="crypt"){
  26. var newText = ""
  27. for (i = 0;i<text.length;i++){
  28. console.log("checking "+text[i]+":");
  29. for (j = 0;j<alf.length;j++){
  30. if (text[i]===alf[j]){
  31. console.log(alf[j]+": true, setting "+alf[(j+2)%54])
  32. newText = newText + alf[(j+2)%54]
  33. }
  34.  
  35. }
  36. }
  37. $("#before").val(newText);
  38. }else{
  39. var newText = ""
  40. for (i = 0;i<text.length;i++){
  41. console.log("checking "+text[i]+":");
  42. for (j = 0;j<alf.length;j++){
  43. if (text[i]===alf[j]){
  44. console.log(alf[j]+": true")
  45. newText = newText + alf[(j+54-2)%54]
  46. }
  47.  
  48. }
  49. }
  50. $("#before").val(newText);
  51. }
  52. });
  53. </script>
  54. </body>
  55.  
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement