Advertisement
Guest User

patou

a guest
Apr 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. function executer(){
  2. alert("Hello world !");
  3. var clef;
  4. clef = document.getElementById("Clef").value;
  5. clef = parseInt(clef);
  6.  
  7. phrase = document.getElementById("Phrase").value;
  8.  
  9. phrase = ChiffreChaine(clef, phrase);
  10.  
  11. document.getElementById("Resultat").value = phrase;
  12. }
  13.  
  14. function main() {
  15. Cesar();
  16. }
  17.  
  18. function AfficherMenu() {
  19. output("Chiffrement César :");
  20. output("Menu : 1 -[ Chiffrez un caractère] 2 -[ Chiffrez un mot] 3 -[ Déchiffrez un mot] 4 -[ Décryptez un mot] 0 -[ Quittez]");
  21. }
  22.  
  23. function Cesar() {
  24. var chaine;
  25. var key, choix;
  26.  
  27. AfficherMenu();
  28. choix = ChoixDansMenu();
  29. while (choix != 0) {
  30. chaine = SaisirMessage();
  31. if (choix >= 1 && choix <= 3) {
  32. key = SaisirClef();
  33. if (choix == 1) {
  34. output(ChiffreCarac(chaine, key));
  35. } else {
  36. if (choix == 2) {
  37. output(ChiffreChaine(key, chaine));
  38. } else {
  39. output(Dechiffrechaine(key, chaine));
  40. }
  41. }
  42. } else {
  43. DecrypteChaine(chaine);
  44. }
  45. AfficherMenu();
  46. choix = ChoixDansMenu();
  47. }
  48. output("Au revoir");
  49. }
  50.  
  51. function ChiffreCarac(car, key) {
  52. var transform;
  53.  
  54. transform = car.charCodeAt(0) - 65;
  55. if (transform >= 0 && transform <= 25) {
  56. if (key > 0) {
  57. } else {
  58. key = 26 + key;
  59. }
  60. car = String.fromCharCode((transform + key) % 26 + 65);
  61. }
  62.  
  63. return car;
  64. }
  65.  
  66. function ChiffreChaine(key, chaine) {
  67. var i;
  68. var message;
  69.  
  70. message = "";
  71. for (i = 0 ; i <= chaine.length - 1 ; i += 1) {
  72. message = message + ChiffreCarac(chaine.charAt(i), key);
  73. }
  74.  
  75. return message;
  76. }
  77.  
  78. function ChoixDansMenu() {
  79. var choix;
  80.  
  81. choix = input("Choix");
  82. choix = EstEntre(choix);
  83.  
  84. return choix;
  85. }
  86.  
  87. function Dechiffrechaine(key, chaine) {
  88. var message;
  89.  
  90. key = key * -1;
  91. message = ChiffreChaine(key, chaine);
  92.  
  93. return message;
  94. }
  95.  
  96. function DecrypteChaine(chaine) {
  97. var i;
  98.  
  99. for (i = -1 ; i >= -25 ; i -= 1) {
  100. output("Clé : " + i * -1 + " - " + ChiffreChaine(i, chaine));
  101. output("");
  102. }
  103. }
  104.  
  105. function EstEntre(choix) {
  106. while (choix < 0 || choix > 4) {
  107. output("Mauvais choix");
  108. choix = input("Choix");
  109. }
  110.  
  111. return choix;
  112. }
  113.  
  114. function SaisirClef() {
  115. var key;
  116.  
  117. output("Rentrez un entier positif");
  118. key = input("Key");
  119.  
  120. return key;
  121. }
  122.  
  123. function SaisirMessage() {
  124. var chaine;
  125.  
  126. output("Rentrez le mot ou le caractere");
  127. chaine = input("Chaine");
  128.  
  129. return chaine;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement