Guest User

Untitled

a guest
Feb 14th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Page Title</title>
  5. </head>
  6.  
  7.  
  8.  
  9. <body>
  10. <h1>Title</h1>
  11.  
  12. <div id="logo">
  13. <p>Logo</p>
  14. </div>
  15.  
  16. <ul style="list-style-type:none">
  17. <li class="button">encode</li>
  18. <li class="button">decode</li>
  19. </ul>
  20.  
  21. <textarea id="input" rows="25" cols="35"></textarea>
  22.  
  23. <textarea id="output" rows="25" cols="35"></textarea>
  24.  
  25.  
  26.  
  27.  
  28.  
  29. <textarea type="text" id="keyword" name="keyword" value="Ssadadsad"></textarea>
  30.  
  31.  
  32. <button id="encrypt" onclick="isEncrypted()">encode</button>
  33. <button id="decrypt" onclick="isDecrypted()">decode</button>
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. </body>
  41.  
  42.  
  43. <script>
  44. var input;
  45. var keyword;
  46. var size= "";
  47. var test1= "";
  48. var output="";
  49. var test2=0;
  50. var test3;
  51. var test4;
  52. var test5;
  53. var test6;
  54.  
  55. var alphabet =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  56.  
  57. function encrypt()
  58. {
  59.  
  60. for (i = 0; i < input.length; i++)
  61. {
  62. test5 = input.charAt(i);
  63. test6 = keyword.charAt(test2);
  64.  
  65. test3 = alphabet.findIndex(arrayIn);
  66. test4 = alphabet.findIndex(arrayKey);
  67. if(input.charAt(i)!=" ")
  68. {
  69.  
  70. if(test3+test4>25)
  71. {
  72. test1=(test3+test4)-26;
  73. size+=alphabet[test1];
  74. }
  75.  
  76. else
  77. {
  78. test1=test4+test3;
  79.  
  80. size+=alphabet[test1];
  81.  
  82.  
  83. }
  84. test2++;
  85. if(test2>=keyword.length)
  86. {
  87. test2=0;
  88. }
  89. }
  90.  
  91. else
  92. {
  93. size+=" ";
  94. }
  95.  
  96. }
  97. }
  98.  
  99.  
  100. function decrypt()
  101. {
  102. for (i = 0; i < input.length; i++)
  103. {
  104.  
  105.  
  106.  
  107. test5 = input.charAt(i);
  108. test6 = keyword.charAt(test2);
  109.  
  110. if(input.charAt(i)!=" ")
  111. {
  112. test3 = alphabet.findIndex(arrayIn);
  113. test4 = alphabet.findIndex(arrayKey);
  114.  
  115.  
  116. if(test3>=test4)
  117. {
  118. test1=test3-test4;
  119. size+=alphabet[test1];
  120. }
  121.  
  122. else
  123. {
  124. test1=test4-test3;
  125. test1= 26-test1;
  126. size+=alphabet[test1];
  127.  
  128.  
  129. }
  130. test2++;
  131. if(test2>=keyword.length)
  132. {
  133. test2=0;
  134. }
  135. }
  136.  
  137. else
  138. {
  139. size+=" ";
  140. }
  141. }
  142. }
  143.  
  144. function arrayIn(element)
  145. {
  146.  
  147. return element==test5;
  148. }
  149.  
  150. function arrayKey(asdas)
  151. {
  152. return asdas==test6;
  153. }
  154.  
  155.  
  156. function isEncrypted()
  157. {
  158. input = document.getElementById("input").value;
  159. keyword = document.getElementById("keyword").value;
  160.  
  161. test2=0;
  162. size="";
  163. encrypt();
  164.  
  165. document.getElementById("output").innerHTML = size;
  166.  
  167. }
  168. function isDecrypted()
  169. {
  170. input = document.getElementById("input").value;
  171. keyword = document.getElementById("keyword").value;
  172.  
  173. test2=0;
  174. size="";
  175. decrypt();
  176.  
  177.  
  178. document.getElementById("output").innerHTML = size;
  179. }
  180. </script>
  181.  
  182. </html>
Add Comment
Please, Sign In to add comment