He worked on Rabin's cryptosystem, encryption was given without problems, but problems arise when decrypting. There are practically no intelligible algorithms and formulas on the Internet, but those that exist work through time namely: the algorithm works correctly with p and q equal to 11 and 19, 19 and 23. For the rest, none of the 4 return options correspond to the source file. I would like to know whether anyone wrote Rabin for arbitrary files or at least some formulas for decrypting the workers. Pieces of the decryption code on the sharps are attached.

private byte[] DecryptOneByte(uint c, int p, int q) { int n = p * q; int[] m = CalculateM(p, q, c); // [0] для p, [1] для q int[] y = AddFuctions.ExtendedEuclidian(p, q); // [0] для p, [1] для q y[1] = p + y[1]; int[] result = new int[4]; result[0] = ((m[0] * q * y[1] + m[1] * p * y[0]) % n); result[1] = (-result[0] + n) % n; result[2] = ((m[0] * q * y[1] - m[1] * p * y[0]) % n); result[3] = (-result[2] + n) % n; for (int i = 0; i < result.Length; i++) { result[i] = Convert(result[i], n); } return new byte[4] { (byte)result[0], (byte)result[1], (byte)result[2], (byte)result[3] }; } private int Convert(int r, int n) { if (r < 0) { return n + r; } else { return r; } } private int[] CalculateM(int p, int q, uint c) { int[] m = new int[2]; m[0] = (int)(Math.Pow((int)c, ((p + 1) / 4)) % p); m[1] = (int)(Math.Pow((int)c, ((q + 1) / 4)) % q); return m; } } public static int[] ExtendedEuclidian(int p, int q) { int[] y = new int[2] { 0, 0 }; gcd(p, q, ref y[0], ref y[1]); return y; } private static int gcd(int a, int b, ref int y0, ref int y1) { if (a == 0) { y0 = 0; y1 = 1; return b; } int x0 = 0; int x1 = 0; int d = gcd(b % a, a, ref x0, ref x1); y0 = x1 - (b / a) * x0; y1 = x0; return d; } 
  • Categorically you should not use cryptography, which is nothing on the Internet. - Vladimir Martyanov

0