Created
September 14, 2023 10:25
-
-
Save nherbaut/8001d4f3cc5bcf91ff3903f110f9e611 to your computer and use it in GitHub Desktop.
Created from MIAGE Code Crafting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Un exemple d'implémentation du Code César. | |
| * | |
| * Pour plus d'info, vous pouvez consulter | |
| * l'<a href="https://fr.wikipedia.org/wiki/Chiffrement_par_d%C3%A9calage"> | |
| * article de Wikipedia</a>. | |
| * | |
| * @author David Gayerie | |
| * | |
| */ | |
| public class AlgoCesar { | |
| public String encrypte(String s) { | |
| StringBuilder sb = new StringBuilder(); | |
| for(char c : s.toCharArray()){ | |
| char newChar = (char) ('a'+((c - 'a' + 23 ) %26)); | |
| sb.append(newChar); | |
| } | |
| return sb.toString(); | |
| } | |
| public static void main(String[] args) { | |
| AlgoCesar algoCesar = new AlgoCesar(); | |
| String resultat = algoCesar.encrypte(""); | |
| System.out.println("".equals(resultat)); | |
| // étape 2 | |
| resultat = algoCesar.encrypte("az"); | |
| System.out.println(resultat); | |
| System.out.println("xw".equals(resultat)); | |
| // étape 3 | |
| /* | |
| resultat = algoCesar.encrypte("AZ"); | |
| System.out.println("XW".equals(resultat)); | |
| */ | |
| // étape 4 | |
| /* | |
| resultat = algoCesar.encrypte("1,000.00"); | |
| System.out.println("1,000.00".equals(resultat)); | |
| */ | |
| // étape 5 | |
| /* | |
| String phrase = "In cryptography, a Caesar cipher is one " | |
| + "of the simplest and most widely known " | |
| + "encryption techniques."; | |
| resultat = algoCesar.encrypte(phrase); | |
| String phraseAttendue = "Fk zovmqldoxmev, x Zxbpxo zfmebo fp lkb " | |
| + "lc qeb pfjmibpq xka jlpq tfabiv hkltk " | |
| + "bkzovmqflk qbzekfnrbp."; | |
| System.out.println(phraseAttendue.equals(resultat)); | |
| */ | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this gist on https://java.miage.dev/?gistId=8001d4f3cc5bcf91ff3903f110f9e611