public byte[] Decrypt(byte[] en) { int[] scr = new int[en.Length]; for (int i = 0; i < scr.Length; i++) { scr[i] = i; } for (int a = 0; a < scr.Length; ++a) { int b = cr.Next(0, scr.Length); if (b <= a) { continue; } int ch = scr[a]; scr[a] = scr[b]; scr[b] = ch; } byte[] retv = new byte[en.Length]; for (int a = 0; a < en.Length; ++a) { retv[scr[a]] = en[a]; } cr = new LegacyCrossRandom(); return(retv); }
public LegacyEnigmaEncryptor(int pin) { enigmaPin = pin; for (int i = 0; i < originalByteMap.Length; i++) { originalByteMap[i] = (byte)i; } instancePin = pin; cr = new LegacyCrossRandom(); }
public LegacyAutokryptexEncryptor(String password, int MaxEncryptors = 6, int seed = 179426447) { cr = new LegacyCrossRandom(); instancePassword = cr.CramString(password, 256); int[] args = new int[256]; for (int i = 0; i < args.Length; i++) { args[i] = instancePassword[i] ^ cr.Next(Int32.MaxValue); } Init(args, MaxEncryptors); }
public void UseInstanceSecret(String secret) { var secretBytes = CramStringPlus(secret, 16); LegacyCrossRandom cr = new LegacyCrossRandom(); for (int i = 0; i < secretBytes.Length; i++) { if (i <= InstanceSecret.Length) { InstanceSecret[i] = Primes[secretBytes[i] % Primes.Length] + cr.Next(Primes.Length ^ secretBytes[i]); } } }
public byte[] Encrypt(byte[] en) { // Brief: Generate enigma strip // set value of character a to value of character b at // position a of the enigma strip. // regenerate the strip for each character. this.enigmaStrip = this.GenerateEnigmaStrip(originalByteMap); for (int a = 0; a < en.Length; ++a) { en[a] = this.enigmaStrip[en[a]]; this.enigmaStrip = this.GenerateEnigmaStrip(this.enigmaStrip); } cr = new LegacyCrossRandom(); return(en); }
public byte[] CramString(String input, int digitCount) { LegacyCrossRandom cr = this; byte[] workset = Fi.StandardEncoding.GetBytes(input); while (workset.Count() > digitCount) { byte ch = workset[0]; workset = workset.Skip(1).ToArray(); workset[cr.Next(workset.Length)] = (byte)(workset[cr.Next(workset.Length)] ^ ch); } while (workset.Count() < digitCount) { var ws = new byte[workset.Count() + 1]; workset.CopyTo(ws, 0); ws[ws.Count() - 1] = (byte)cr.Next(byte.MaxValue); workset = ws; } return(workset); }
public byte[] Decrypt(byte[] en) { // Brief: Generate enigma strip // set value of character a to index of character b at // position a of the original byte strip. // regenerate the strip for each character. this.enigmaStrip = this.GenerateEnigmaStrip(originalByteMap); for (int a = 0; a < en.Length; ++a) { var index = -1; for (int x = 0; x < enigmaStrip.Length; x++) { if (enigmaStrip[x] == en[a]) { index = x; break; } } en[a] = originalByteMap[index]; this.enigmaStrip = this.GenerateEnigmaStrip(this.enigmaStrip); } cr = new LegacyCrossRandom(); return(en); }
public LegacyBinaryScramble(int pin) { instancePin = pin; cr = new LegacyCrossRandom(); }