Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
4,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. $("#leForm").submit(function(){
  2. // 2D Encryption
  3. var input = $("#resultKeyAttempt").val();
  4. theKey = "kpoisaijdieyjaf";
  5. var theAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz";
  6.  
  7. // Validate theKey:
  8. theKey = theKey.toUpperCase();
  9. var theKeysLength = theKey.length;
  10. var i;
  11. var adjustedKey = "";
  12. for(i = 0; i < theKeysLength; i ++)
  13. {
  14. var currentKeyChar = theAlphabet.indexOf(theKey.charAt(i));
  15. if(currentKeyChar < 0)
  16. continue;
  17. adjustedKey += theAlphabet.charAt(currentKeyChar);
  18. }
  19. theKey = adjustedKey;
  20. theKeysLength = theKey.length;
  21.  
  22. // Transform input:
  23. var inputLength = input.length;
  24. var output = "";
  25. var theKeysCurrentIndex = 0;
  26. for(i = 0; i < inputLength; i ++)
  27. {
  28. var currentChar = input.charAt(i);
  29. var currentCharValue = theAlphabet.indexOf(currentChar);
  30. if(currentCharValue < 0)
  31. {
  32. output += currentChar;
  33. continue;
  34. }
  35. var lowercase = currentCharValue >= 26 ? true : false;
  36. currentCharValue += theAlphabet.indexOf(theKey.charAt(theKeysCurrentIndex));
  37. currentCharValue += 26;
  38. if(lowercase)
  39. currentCharValue = currentCharValue % 26 + 26;
  40. else
  41. currentCharValue %= 26;
  42. output += theAlphabet.charAt(currentCharValue);
  43. theKeysCurrentIndex =(theKeysCurrentIndex + 1) % theKeysLength;
  44. }
  45.  
  46. // Check result for validity
  47. $("#resultDiv").hide("fast", function(){
  48. if(output == "DwsDagmwhziArpmogWaSmmckwhMoEsmgmxlivpDttfjbjdxqBwxbKbCwgwgUyam")
  49. $('#resultDiv').html("<p>Yeah, that's correct</p>");
  50. else
  51. $('#resultDiv').html("<p>No, that's not correct</p>");
  52. $("#resultDiv").show("slow");
  53. });
  54. // Output the "output" variable to the HTML for viewing
  55. /*
  56. $("#resultDiv").hide("fast", function(){
  57. $('#resultDiv').html("Encrypted Output: " + output);
  58. $("#resultDiv").show("slow");
  59. });
  60. */
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement