1# This file contains test vectors for whether B is a Miller-Rabin composite 2# witness for W. W must be odd and B must satisfy 1 <= B <= W-1. 3# 4# The following Python function may be used to check values. 5# 6# def is_miller_rabin_witness(w, b): 7# # Variable names taken from FIPS 186-4 C.3.1 but the algorithm skips a 8# # couple of optimizations in the FIPS formulation. 9# m = w - 1 10# a = 0 11# while m&1 == 0: 12# a += 1 13# m //= 2 14# # b is a composite witness for w iff the following are true: 15# # - b^m != 1 (mod w) 16# # - b^(m*2^j) != -1 (mod w), for 0 <= j < a 17# z = pow(b, m, w) 18# if z == 1: 19# # b^m = 1 (mod w) 20# return False 21# for j in range(a): 22# if z == w-1: 23# # b^(m*2^j) = -1 (mod w) 24# return False 25# z = (z * z) % w 26# # At this point, z is b^(w-1) (mod w). If z is not 1, w has failed the 27# # Fermat test and is composite. If z is 1, the value of z immediately 28# # before it became 1 is a non-trivial root of unity and w is composite. 29# return True 30 31# Exhaustively test a small prime. 32 33Result = PossiblyPrime 34W = 7 35B = 1 36 37Result = PossiblyPrime 38W = 7 39B = 2 40 41Result = PossiblyPrime 42W = 7 43B = 3 44 45Result = PossiblyPrime 46W = 7 47B = 4 48 49Result = PossiblyPrime 50W = 7 51B = 5 52 53Result = PossiblyPrime 54W = 7 55B = 6 56 57 58# Random large inputs which try to cover a few cases. The nontrivial square root 59# case appears to be difficult to hit randomly. 60 61# b^m = w-1 62Result = PossiblyPrime 63W = d6b4ffc7cf70b2a2fc5d6023015875504d40e3dcce7c2e6b762c3de7bb806a5074144e7054198dabf53d23108679ccc541d5a99efeb1d1abaf89e0dbcead2a8b 64B = fabbafdbec6494ddb5ea4bf458536e87082369b0e53a200ed413f3e64b2fddc7c57c565710fbe73fae5b188fce97d8dcca74c2b5d90906c96d3c2c358a735cd 65 66# b^m = w-1 67Result = PossiblyPrime 68W = 52cc61c42b341ad56dc11495e7cb2fe31e506b9e99522efbf44cd7c28468d3833c5e360f3c77b0aa43c0495c4e14665ab0d7cee9294c722f0de47d4401828401 69B = 3bdc9639c0fc2e77ab48d46e0b4ac6529c11c900e8fe4d82d75767c0556feb23d3f42d4924d16876a743feb386b7b84c7fd16a6c252f662faf0024d19972e62f 70 71# b^m = w-1 72Result = PossiblyPrime 73W = cff9897aa7dce0f2afad262b2de57d301305de717f3539c537c4ce062f8cb70df13fbc1eb4a3b9f0958a8810d1ca9042b4f23334b285a15fee3fc66498761d4b 74B = 9ceb43132fddf9ee4104ea1cb3eb2253c1d7f803f05f0305de9e31a17dd75832f47b8bf189a9b7ca0905f2a7470d9c6349080f481ff1708696fa12d972e7d7ba 75 76# Some b^(m*2^j) = w-1 77Result = PossiblyPrime 78W = 67d1825dad5344170e65247a87aef1634a1b32bdc22f2f04d9d2959767bb5a27610fba55cd607e0f9fdd9fbb0f7f98e40d5e1eb2f52318fb5be4dbfd30d38861 79B = 260fb14724ff80984736859d8755ee98b25bcb56db9fde1db001a1e1273374034c5b75fd60b3710c7a08ce7d390776f010f384d4e32943cf0c477497d53e9e05 80 81# Some b^(m*2^j) = w-1 82Result = PossiblyPrime 83W = ad0bc85b58aaa204177aa9431a40929beb1cbea2dd6f66a25cc54600013213b225ba881805661df43f4208965ada7aacc8095d07d3cbef1a7bbfaae8b745f731 84B = 3d9310f20e9c80269fa6830c7e1a6f02fc5c58646001a9ef6b8b3e496602ff22c3dcb2ddb6a221723fc1722ce237fb46f7a7bb2945e415c8839b15a972f076c9 85 86# Some b^(m*2^j) = w-1 87Result = PossiblyPrime 88W = b25c917f55f6c7b596921daba919f35039e5d805119c1587e99849dd7104460c86214f162a6f17aea847bc7f3859e59f2991d457059511972ef373d4bc75e309 89B = a1f10b261dee84619b0423201d46af19eef9ec0612cf947c4d5c36c0c4b28207f75967e69452eabad0a5dcd28f27f7a8a7ed9c8b3e5026c6e0ba5634d94c2d44 90 91# b^m = 1 92Result = PossiblyPrime 93W = d3eeb0eff05b6992e9fa61b02755e155f4aae28c6e45ddb874edd86acdd2d83d18a20e0e00d8b8bc94b92d14fc3f41ced6ababe8ac98c7730c075dbe0f699369 94B = 6b7717269c6225203681a1cacec87cacd83003ec6e9e3f04effcc4f86634770c0860e1f2770b8f303719a44949664a1094205a99d95a0856758fed66d690105e 95 96# b^m = 1 97Result = PossiblyPrime 98W = 64561b8d9aa50340c3a01ccb3e6e17f5023513661c012be288f3900a3ca76890e67290b9560fa1d480f9d2aacccca581b5690636665f243fa13aff5d0bff12d3 99B = 1f5ff70d3d60671ebc5fbfca731898a04438053dbc3c841e6335f487e457d92d9efb5d506d5bef6872d58d12b9a41c950bfc38d12ed977c90eacdd6535b811a0 100 101# b^m = 1 102Result = PossiblyPrime 103W = 69c63fbf44df21b0ed0ee929a740c12d1f3f064da0dcd9d509f31fa45fa27d1a759ab5a9f6f1040d7ee90a0b1e68f779273c41ea1c1198fd547ff6bd70c7e787 104B = 5f7996a9bbfd8fd88e472220b70077bfdacdd63d88885134431f024c2acb7126827b174eb093eb5313f07bb5461de9b0feb7d77ca2c39c2a323a150f33ea525f 105 106# End of iteration 107Result = Composite 108W = 28cc3e08c44571c6dcb98a9ab8b4f3e2b16e1f884997d94a3188bcbb7f1b7cdaecdae8329c013ec8f75dc00004da0039943e4262cd080b16a42910102e00dddb 109B = 512061ab1c69931c2fa0bb89d8d09f3c9209230bf927ddd6fb6a72075f967ed3c4dbb5f437bf4d31ca7344782b22011ad56609dc19aed65319bababfc13dd7 110 111# End of iteration 112Result = Composite 113W = 4eeb7b4d371c45fe8586fee3b1efd792176b70f6cc2698dfa1dd028366626febe0199c3c5f77a5c3cad0057a04767383051d41965255d03681b2a37edad34a9b 114B = 4afc2e85f84017b3fd6967a227eb74c8297b40ea02733d9513bff9b3f01081963f25872f4254afc4e9321eea35b2a1e42eadb186fcc84f2f30f4a994350b93b8 115 116# End of iteration 117Result = Composite 118W = 8e35a959555dd2eb66c65cee3c264071d20671f159e1f9896f1d0ceb041905fcf053eacc189de317c3ee6f93901223cbf30d5b7ddbbdab981790e2f6397e6803 119B = 44c0153759309ec4e5b1e59d57c1b126545ef7ea302b6e43561df4d16068b922389d6924f01c945d9080d1f93a0732599bdedae72d6d590839dc0884dd860441 120 121 122# 0x6c1 = 1729 = 7 * 13 * 19 is a Fermat pseudoprime. 123 124# Found non-trivial square root 125Result = Composite 126W = 6c1 127B = b8 128 129# End of iteration 130Result = Composite 131W = 6c1 132B = 111 133 134# End of iteration 135Result = Composite 136W = 6c1 137B = 11d 138 139# Found non-trivial square root 140Result = Composite 141W = 6c1 142B = 19c 143 144# Found non-trivial square root 145Result = Composite 146W = 6c1 147B = 223 148 149# End of iteration 150Result = Composite 151W = 6c1 152B = 3aa 153 154# Found non-trivial square root 155Result = Composite 156W = 6c1 157B = 653 158 159 160# 1729 has a number of false witnesses. 161 162# b^m = 1 163Result = PossiblyPrime 164W = 6c1 165B = 78 166 167# b^m = 1 168Result = PossiblyPrime 169W = 6c1 170B = eb 171 172# b^m = w-1 173Result = PossiblyPrime 174W = 6c1 175B = 178 176 177# b^m = w-1 178Result = PossiblyPrime 179W = 6c1 180B = 178 181 182# b^m = w-1 183Result = PossiblyPrime 184W = 6c1 185B = 1aa 186 187# b^m = 1 188Result = PossiblyPrime 189W = 6c1 190B = 271 191 192# b^m = 1 193Result = PossiblyPrime 194W = 6c1 195B = 2b2 196 197 198# 1 and W-1 are always nonwitnesses. 199Result = PossiblyPrime 200W = 6c1 201B = 1 202 203Result = PossiblyPrime 204W = 6c1 205B = 6c0 206 207 208# https://kconrad.math.uconn.edu/blurbs/ugradnumthy/millerrabin.pdf, examples 209# 3.1 and 3.2 has a complete list of false witnesses for 65 = 0x41 and 210# 85 = 0x55. 211 212# b^m = 1 213Result = PossiblyPrime 214W = 41 215B = 1 216 217# Some b^(m*2^j) = w-1 218Result = PossiblyPrime 219W = 41 220B = 8 221 222# Some b^(m*2^j) = w-1 223Result = PossiblyPrime 224W = 41 225B = 12 226 227# Some b^(m*2^j) = w-1 228Result = PossiblyPrime 229W = 41 230B = 2f 231 232# Some b^(m*2^j) = w-1 233Result = PossiblyPrime 234W = 41 235B = 39 236 237# b^m = w-1 238Result = PossiblyPrime 239W = 41 240B = 40 241 242# b^m = 1 243Result = PossiblyPrime 244W = 55 245B = 1 246 247# Some b^(m*2^j) = w-1 248Result = PossiblyPrime 249W = 55 250B = d 251 252# Some b^(m*2^j) = w-1 253Result = PossiblyPrime 254W = 55 255B = 26 256 257# Some b^(m*2^j) = w-1 258Result = PossiblyPrime 259W = 55 260B = 2f 261 262# Some b^(m*2^j) = w-1 263Result = PossiblyPrime 264W = 55 265B = 48 266 267# b^m = w-1 268Result = PossiblyPrime 269W = 55 270B = 54 271 272# Other witnesses for 65 and 85 will report composite: 273 274# Found non-trivial square root 275Result = Composite 276W = 41 277B = 2c 278 279# End of iteration 280Result = Composite 281W = 41 282B = 16 283 284# End of iteration 285Result = Composite 286W = 41 287B = 14 288 289# End of iteration 290Result = Composite 291W = 41 292B = 2 293 294# End of iteration 295Result = Composite 296W = 41 297B = 3a 298 299# End of iteration 300Result = Composite 301W = 55 302B = 40 303 304# End of iteration 305Result = Composite 306W = 55 307B = 7 308 309# End of iteration 310Result = Composite 311W = 55 312B = 23 313 314# End of iteration 315Result = Composite 316W = 55 317B = 2e 318 319# End of iteration 320Result = Composite 321W = 55 322B = 2a 323