1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lcrypt
{
public static class Cryptage
{
private static List<string> Tableau;
private static string Crypte;
static int indice;
public static string Crypter(string phrase)
{
indice = new Random((int)DateTime.Now.Ticks).Next(2, 100);
Crypte = (((indice * indice) / 2) + 6).ToString() + "|";
Tableau = new List<string>();
foreach (char ch in phrase)
Tableau.Add(ch.ToString());
crypteur();
return Crypte;
}
private static void crypteur()
{
int essaie = 0;
for (int i = 0; i < Tableau.Count; i++)
{
if (int.TryParse(Tableau[i], out essaie))
Crypte += retournerLettre((Convert.ToInt32(Tableau[i]))) + "|";
else
{
if (RenvoyerChiffre(Tableau[i]) == 0)
{
if (Tableau[i] == "|")
Crypte += "k|";
else
Crypte += Tableau[i] + "|";
}
else
Crypte += ((((RenvoyerChiffre(Tableau[i]) * indice) / 2) + 6) * 7).ToString() + "|";
}
}
}
private static int RenvoyerChiffre(string a)
{
switch (a)
{
case "a":
return 1;
case "b":
return 2;
case "c":
return 3;
case "d":
return 4;
case "e":
return 5;
case "f":
return 6;
case "g":
return 7;
case "h":
return 8;
case "i":
return 9;
case "j":
return 10;
case "k":
return 11;
case "l":
return 12;
case "m":
return 13;
case "n":
return 14;
case "o":
return 15;
case "p":
return 16;
case "q":
return 17;
case "r":
return 18;
case "s":
return 19;
case "t":
return 20;
case "u":
return 21;
case "v":
return 22;
case "w":
return 23;
case "x":
return 24;
case "y":
return 25;
case "z":
return 26;
case "A":
return 27;
case "B":
return 28;
case "C":
return 29;
case "D":
return 30;
case "E":
return 31;
case "F":
return 32;
case "G":
return 33;
case "H":
return 34;
case "I":
return 35;
case "J":
return 36;
case "K":
return 37;
case "L":
return 38;
case "M":
return 39;
case "N":
return 40;
case "O":
return 41;
case "P":
return 42;
case "Q":
return 43;
case "R":
return 44;
case "S":
return 45;
case "T":
return 46;
case "U":
return 47;
case "V":
return 48;
case "W":
return 49;
case "X":
return 50;
case "Y":
return 51;
case "Z":
return 52;
default:
return 0;
}
}
private static string retournerLettre(int a)
{
switch (a)
{
case 1:
return "a";
case 2:
return "b";
case 3:
return "c";
case 4:
return "d";
case 5:
return "e";
case 6:
return "f";
case 7:
return "g";
case 8:
return "h";
case 9:
return "i";
case 0:
return "j";
default:
return null;
}
}
}
} |
Partager