public int[] testHexToByte() { int[] passed = new int[2]; passed[1] = 1; string even = "abdc"; string odd = "abc"; byte[] evenArray = OTPworker.HexStringToByteArray(even); byte[] oddArray = OTPworker.HexStringToByteArray(odd); // If it's gotten this far, it works passed[0] = 1; return(passed); }
// Test the OTP generator to make sure it outputs the same pad given the same seed public int[] testOtpGenerator2() { int[] passed = new int[2]; int size = 16; string s = "a"; string result1 = ""; string result2 = ""; byte[] seed = OTPworker.HexStringToByteArray(s); byte[] output = new byte[size]; for (int i = 0; i < 1000; i++) { passed[1] += 1; if (s.Length < 30) { int rand = Random.Range(0, 9); s += rand.ToString(); } else { s = "b"; } OTPworker.OTPGenerator(output, size, seed); result1 = OTPworker.ByteArrayToHex(output); result2 = OTPworker.ByteArrayToHex(output); if (result1 == result2) { passed[0] += 1; } else { Debug.Log("OTP generator test failed. Seed: " + result1 + " Result: " + result2); } } return(passed); }
// Test the OTP generator to make sure it outputs the same pad given the same seed public int[] testOtpGenerator() { int[] passed = new int[2]; int size = 16; string s1 = "9876abcdef"; string s2 = "1234567890"; string s3 = "0245789bce"; byte[] seed1 = OTPworker.HexStringToByteArray(s1); byte[] seed2 = OTPworker.HexStringToByteArray(s2); byte[] seed3 = OTPworker.HexStringToByteArray(s3); byte[] output = new byte[size]; List <string> result1 = new List <string>(); List <string> result2 = new List <string>(); List <string> result3 = new List <string>(); for (int i = 0; i < 10; i++) { OTPworker.OTPGenerator(output, size, seed1); result1.Add(OTPworker.ByteArrayToHex(output)); } for (int i = 0; i < 10; i++) { OTPworker.OTPGenerator(output, size, seed2); result2.Add(OTPworker.ByteArrayToHex(output)); } for (int i = 0; i < 10; i++) { OTPworker.OTPGenerator(output, size, seed3); result3.Add(OTPworker.ByteArrayToHex(output)); } for (int i = 1; i < result1.Count; i++) { passed[1] += 3; if (result1[0] != result1[i]) { Debug.Log("String mismatch in result1"); Debug.Log("RandomBytesDeterministic test failed"); } else { passed[0] += 1; } if (result2[0] != result2[i]) { Debug.Log("String mismatch in result2"); Debug.Log("RandomBytesDeterministic test failed"); } else { passed[0] += 1; } if (result3[0] != result3[i]) { Debug.Log("String mismatch in result3"); Debug.Log("RandomBytesDeterministic test failed"); } else { passed[0] += 1; } } return(passed); }