using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace crypto { class CryptoPerso { //Basé sur le cryptage césar private const string alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXTZ0123456789&@,?;.:/ "; public string Alphabet { get { return alphabet; } set { } } private byte[] alphabetArray = Encoding.ASCII.GetBytes(alphabet); private byte[] textArray; public CryptoPerso() { } public byte[] StrToInt(string texte) { List tmp = new List(); textArray = Encoding.ASCII.GetBytes(texte); for(int i=0; i tmp = new List(); for (int i = 0; i < textArray.Length; i++) { tmp.Add(alphabetArray[textArray[i]]); } return tmp.ToArray(); } public string Crypt(string texte, string pw) { try { byte[] texteInt = StrToInt(texte); byte[] pwInt = StrToInt(pw); List tmp = new List(); for (int i = 0; i < texteInt.Length; i++) { byte a = (byte)((texteInt[i] + pwInt[i % (pwInt.Length)]) % (alphabetArray.Length)); tmp.Add(a); } return Encoding.ASCII.GetString(IntToStr(tmp.ToArray())); } catch(Exception e) { warn w = new warn("ERREUR : "+e.ToString()); w.Show(); Console.WriteLine(e.ToString()); return null; } } public string decryptage(string texte, string pw) { try { byte[] texteInt = StrToInt(texte); byte[] pwInt = StrToInt(pw); List tmp = new List(); for (int i = 0; i < texteInt.Length; i++) { if (texteInt[i] < pwInt[i % (pwInt.Length)]) texteInt[i] += (byte)(alphabet.Length); byte a = (byte)((texteInt[i] - pwInt[i % (pwInt.Length)])); tmp.Add(a); } return Encoding.ASCII.GetString(IntToStr(tmp.ToArray())); } catch (Exception e) { warn w = new warn("ERREUR : "+e.ToString()); w.Show(); Console.WriteLine(e.ToString()); return null; } } } }