Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function executer(){
- alert("Hello world !");
- var clef;
- clef = document.getElementById("Clef").value;
- clef = parseInt(clef);
- phrase = document.getElementById("Phrase").value;
- phrase = ChiffreChaine(clef, phrase);
- document.getElementById("Resultat").value = phrase;
- }
- function main() {
- Cesar();
- }
- function AfficherMenu() {
- output("Chiffrement César :");
- output("Menu : 1 -[ Chiffrez un caractère] 2 -[ Chiffrez un mot] 3 -[ Déchiffrez un mot] 4 -[ Décryptez un mot] 0 -[ Quittez]");
- }
- function Cesar() {
- var chaine;
- var key, choix;
- AfficherMenu();
- choix = ChoixDansMenu();
- while (choix != 0) {
- chaine = SaisirMessage();
- if (choix >= 1 && choix <= 3) {
- key = SaisirClef();
- if (choix == 1) {
- output(ChiffreCarac(chaine, key));
- } else {
- if (choix == 2) {
- output(ChiffreChaine(key, chaine));
- } else {
- output(Dechiffrechaine(key, chaine));
- }
- }
- } else {
- DecrypteChaine(chaine);
- }
- AfficherMenu();
- choix = ChoixDansMenu();
- }
- output("Au revoir");
- }
- function ChiffreCarac(car, key) {
- var transform;
- transform = car.charCodeAt(0) - 65;
- if (transform >= 0 && transform <= 25) {
- if (key > 0) {
- } else {
- key = 26 + key;
- }
- car = String.fromCharCode((transform + key) % 26 + 65);
- }
- return car;
- }
- function ChiffreChaine(key, chaine) {
- var i;
- var message;
- message = "";
- for (i = 0 ; i <= chaine.length - 1 ; i += 1) {
- message = message + ChiffreCarac(chaine.charAt(i), key);
- }
- return message;
- }
- function ChoixDansMenu() {
- var choix;
- choix = input("Choix");
- choix = EstEntre(choix);
- return choix;
- }
- function Dechiffrechaine(key, chaine) {
- var message;
- key = key * -1;
- message = ChiffreChaine(key, chaine);
- return message;
- }
- function DecrypteChaine(chaine) {
- var i;
- for (i = -1 ; i >= -25 ; i -= 1) {
- output("Clé : " + i * -1 + " - " + ChiffreChaine(i, chaine));
- output("");
- }
- }
- function EstEntre(choix) {
- while (choix < 0 || choix > 4) {
- output("Mauvais choix");
- choix = input("Choix");
- }
- return choix;
- }
- function SaisirClef() {
- var key;
- output("Rentrez un entier positif");
- key = input("Key");
- return key;
- }
- function SaisirMessage() {
- var chaine;
- output("Rentrez le mot ou le caractere");
- chaine = input("Chaine");
- return chaine;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement