diff --git a/doc/kryptools.ipynb b/doc/kryptools.ipynb index fdec51a..9367d4a 100644 --- a/doc/kryptools.ipynb +++ b/doc/kryptools.ipynb @@ -915,6 +915,37 @@ "euler_phi(n), carmichael_lambda(n), moebius_mu(n)" ] }, + { + "cell_type": "markdown", + "id": "43fd2639-9099-42a3-a5ed-e50a4c628981", + "metadata": {}, + "source": [ + "A test if a number is a [Carmichael number](https://en.wikipedia.org/wiki/Carmichael_number):" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "8dc5326e-075b-41ae-a9d8-3d305384809f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from kryptools import is_carmichael_number\n", + "\n", + "is_carmichael_number(561)" + ] + }, { "cell_type": "markdown", "id": "76fb4f61-d902-4432-92c9-7383c4e068cd", @@ -925,7 +956,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "c71e085a-8c47-4714-bca3-de82db263d08", "metadata": {}, "outputs": [ @@ -935,7 +966,7 @@ "6" ] }, - "execution_count": 30, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -964,7 +995,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "0e7ff518-ca8a-4132-a428-a9a623c40219", "metadata": {}, "outputs": [ @@ -974,7 +1005,7 @@ "[8589934609, 8589934621, 8589934627, 8589934631, 8589934651]" ] }, - "execution_count": 31, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -1008,7 +1039,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "f55d33f5-0576-4214-b9b1-980559331d4b", "metadata": {}, "outputs": [ @@ -1018,7 +1049,7 @@ "[953188841, 2267150034, 7376225206, 341660855, 3090211041]" ] }, - "execution_count": 32, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -1048,7 +1079,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "cfe6f3fc-af1e-467a-bbe7-6ab726836ca3", "metadata": {}, "outputs": [], @@ -1078,7 +1109,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "49a0a92d-e58d-49e5-b9fb-79c4d30c200a", "metadata": {}, "outputs": [ @@ -1098,7 +1129,7 @@ "{59649589127497217: 1, 5704689200685129054721: 1}" ] }, - "execution_count": 34, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -1120,7 +1151,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "e8788850-9df6-45d9-9b3f-3ce7b1db13cb", "metadata": {}, "outputs": [ @@ -1130,7 +1161,7 @@ "(10, 2)" ] }, - "execution_count": 35, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -1151,7 +1182,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 37, "id": "315a12c6-cd1f-49fa-8599-6cb6a6526d33", "metadata": {}, "outputs": [ @@ -1161,7 +1192,7 @@ "(9973, 100)" ] }, - "execution_count": 36, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -1190,7 +1221,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "9a629204-562c-44eb-a012-7345b97035b5", "metadata": {}, "outputs": [ @@ -1200,7 +1231,7 @@ "[487, 1709]" ] }, - "execution_count": 37, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -1221,7 +1252,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "39f76a97-1b88-4b95-aac7-bf403043d7b7", "metadata": {}, "outputs": [ @@ -1231,7 +1262,7 @@ "1709" ] }, - "execution_count": 38, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1252,7 +1283,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "6c0cb7c6-03e5-469f-8420-496813bd26ea", "metadata": {}, "outputs": [ @@ -1262,7 +1293,7 @@ "487" ] }, - "execution_count": 39, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -1283,7 +1314,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "e68d0db0-7d1d-4a00-ad6e-10656c829708", "metadata": {}, "outputs": [ @@ -1293,7 +1324,7 @@ "487" ] }, - "execution_count": 40, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -1314,7 +1345,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "3b7c0474-835b-4b10-b0d3-a7b8f62eff23", "metadata": {}, "outputs": [ @@ -1324,7 +1355,7 @@ "1709" ] }, - "execution_count": 41, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1345,7 +1376,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "id": "8ee9854b-6ce0-43b6-906d-98f52fb74d8e", "metadata": {}, "outputs": [ @@ -1355,7 +1386,7 @@ "1709" ] }, - "execution_count": 42, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1384,7 +1415,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "46ab20cc-8d39-4d7b-baef-f411cf34deb7", "metadata": {}, "outputs": [], @@ -1417,7 +1448,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "66ae327c-ff14-4bff-b12d-330c1787cd6b", "metadata": {}, "outputs": [], @@ -1440,7 +1471,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "d1ce2beb-4e60-4a56-9943-d47f1945f13a", "metadata": {}, "outputs": [], @@ -1463,7 +1494,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 47, "id": "fb231c7c-293f-4353-8048-1de3d26568e1", "metadata": {}, "outputs": [], @@ -1486,7 +1517,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "id": "ad8d5929-488e-44bc-9263-91044a2886d4", "metadata": {}, "outputs": [ @@ -1518,7 +1549,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "id": "882543ac-a2f7-4448-93bd-d9385d3457f6", "metadata": {}, "outputs": [ @@ -1559,7 +1590,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 50, "id": "4626c758-753b-4d3a-9ed0-99038ca5f280", "metadata": {}, "outputs": [ @@ -1570,7 +1601,7 @@ "[ 35 ]" ] }, - "execution_count": 49, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1593,7 +1624,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 51, "id": "8a2f83a9-7114-43a1-baee-7f6bb6c45f30", "metadata": {}, "outputs": [ @@ -1604,7 +1635,7 @@ "[ 3 ]" ] }, - "execution_count": 50, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -1623,7 +1654,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 52, "id": "ef4a7e98-4d55-482b-a264-6aab3283e6ec", "metadata": {}, "outputs": [ @@ -1634,7 +1665,7 @@ "[ 1, 2, 3 ]" ] }, - "execution_count": 51, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -1654,7 +1685,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 53, "id": "3bec64e6-937f-4041-a710-cf42c95a8689", "metadata": {}, "outputs": [ @@ -1666,7 +1697,7 @@ "[ 7, 8, 12 ]" ] }, - "execution_count": 52, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1689,7 +1720,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 54, "id": "ab222100-fc64-49b9-b5ef-2d6ae719f15c", "metadata": {}, "outputs": [ @@ -1701,7 +1732,7 @@ "[ 0, 0, 1 ]" ] }, - "execution_count": 53, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -1720,7 +1751,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 55, "id": "a99ed976-cbdd-4ce7-8a97-efcee7fd510d", "metadata": {}, "outputs": [ @@ -1730,7 +1761,7 @@ "-9" ] }, - "execution_count": 54, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -1749,7 +1780,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 56, "id": "64294f1f-d3ef-41b0-ad59-d68e69c89aba", "metadata": {}, "outputs": [ @@ -1770,7 +1801,7 @@ "[ 0, 0, 1 ]" ] }, - "execution_count": 55, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -1791,7 +1822,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 57, "id": "47961b0f-e632-4d1c-9445-de3c217bce10", "metadata": {}, "outputs": [ @@ -1801,7 +1832,7 @@ "2" ] }, - "execution_count": 56, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -1815,7 +1846,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 58, "id": "d9cfb165-6e94-413b-9a91-5c5aa3870aa3", "metadata": {}, "outputs": [ @@ -1836,7 +1867,7 @@ "[ 0, 0, 1 ]" ] }, - "execution_count": 57, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1865,7 +1896,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 59, "id": "0f5a048b-767e-4848-bb23-c898365ee9dc", "metadata": {}, "outputs": [ @@ -1877,7 +1908,7 @@ "[ 0, 0, 1 ]" ] }, - "execution_count": 58, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1899,7 +1930,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 60, "id": "61bad2d5-2fad-4f5a-b4cf-206fca8e09fd", "metadata": {}, "outputs": [ @@ -1910,7 +1941,7 @@ "[ 0, 1 ]" ] }, - "execution_count": 59, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -1934,7 +1965,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 61, "id": "5712d013-c037-4b03-9f62-13fdaaae855b", "metadata": {}, "outputs": [ @@ -1944,7 +1975,7 @@ "5.0" ] }, - "execution_count": 60, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -1965,7 +1996,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 62, "id": "0c56dbdc-caa4-4783-8c2f-8f586a8dc4a1", "metadata": {}, "outputs": [ @@ -1975,7 +2006,7 @@ "0.3521856535823236" ] }, - "execution_count": 61, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -1996,7 +2027,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 63, "id": "c3f8c523-114c-46b9-968d-4eb31615de4b", "metadata": {}, "outputs": [ @@ -2014,7 +2045,7 @@ "[ 0 ]" ] }, - "execution_count": 62, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -2040,7 +2071,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 64, "id": "b8ba76ae-092c-4f12-9a05-0b33fd54ebb2", "metadata": {}, "outputs": [ @@ -2058,7 +2089,7 @@ "[ 0 ]" ] }, - "execution_count": 63, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -2082,7 +2113,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 65, "id": "bd6ea8c7-85ba-4b8d-97d6-f3176e9a22d4", "metadata": {}, "outputs": [ @@ -2100,7 +2131,7 @@ "[ 0 ]" ] }, - "execution_count": 64, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -2125,7 +2156,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 66, "id": "ee41707c-8d92-468d-9a94-18b6bd44053c", "metadata": {}, "outputs": [ @@ -2137,7 +2168,7 @@ "[ 1, -1, 1 ]" ] }, - "execution_count": 65, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } @@ -2160,7 +2191,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 67, "id": "694c25e5-d01f-4acf-ab57-69bffb0fb9a8", "metadata": {}, "outputs": [ @@ -2172,7 +2203,7 @@ "[ 4, 2, 9 ]" ] }, - "execution_count": 66, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -2201,7 +2232,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 68, "id": "df0886b4-54d8-4fe7-a665-e9b908c41060", "metadata": {}, "outputs": [ @@ -2214,7 +2245,7 @@ "[ 49, -45, 29, 735 ]" ] }, - "execution_count": 67, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -2242,7 +2273,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 69, "id": "6ff2fa77-eebd-4f1c-a894-f3a9c294bfc7", "metadata": {}, "outputs": [ @@ -2252,7 +2283,7 @@ "0.9962449639096419" ] }, - "execution_count": 68, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -2271,7 +2302,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 70, "id": "e9009a78-4e62-40a8-b231-987bd4e42a86", "metadata": {}, "outputs": [ @@ -2281,7 +2312,7 @@ "367.329164515002" ] }, - "execution_count": 69, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -2304,7 +2335,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 71, "id": "5a07021d-93e6-41fe-8a66-523c0faad0f9", "metadata": {}, "outputs": [ @@ -2317,7 +2348,7 @@ "[ 823300, -1867613, 1986482, -1699706 ]" ] }, - "execution_count": 70, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -2337,7 +2368,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 72, "id": "7ef33518-5192-4603-8df3-21f4524aaf76", "metadata": {}, "outputs": [ @@ -2347,7 +2378,7 @@ "0.0002031966189726793" ] }, - "execution_count": 71, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -2366,7 +2397,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 73, "id": "fbef8bf6-10be-4aea-b672-ddadfa0b705f", "metadata": {}, "outputs": [ @@ -2376,7 +2407,7 @@ "0.015520618275460585" ] }, - "execution_count": 72, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -2395,7 +2426,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 74, "id": "7a652c7d-9726-47cc-b2a6-ad22c4dec5f4", "metadata": {}, "outputs": [ @@ -2408,7 +2439,7 @@ "[ 15226425 ]" ] }, - "execution_count": 73, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } @@ -2436,7 +2467,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 75, "id": "4e9e3dfb-564c-4a59-9d71-9e4be59b4cac", "metadata": {}, "outputs": [ @@ -2446,7 +2477,7 @@ "True" ] }, - "execution_count": 74, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } @@ -2466,7 +2497,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 76, "id": "b81fe34e-3337-484c-900d-21fa9d7a2945", "metadata": {}, "outputs": [ @@ -2476,7 +2507,7 @@ "False" ] }, - "execution_count": 75, + "execution_count": 76, "metadata": {}, "output_type": "execute_result" } @@ -2496,7 +2527,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 77, "id": "a871a91f-fff2-4645-b868-c31972228de2", "metadata": {}, "outputs": [ @@ -2506,7 +2537,7 @@ "True" ] }, - "execution_count": 76, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } @@ -2534,7 +2565,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 78, "id": "d3c69787-da17-4cd3-b282-a68ee4d177e6", "metadata": {}, "outputs": [ @@ -2544,7 +2575,7 @@ "(2 x^2 + 2, 4 x^3 + 3 x^2 + 2 x + 1)" ] }, - "execution_count": 77, + "execution_count": 78, "metadata": {}, "output_type": "execute_result" } @@ -2568,7 +2599,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 79, "id": "93326765-bb08-4c15-9d1a-97b1440ba986", "metadata": {}, "outputs": [ @@ -2578,7 +2609,7 @@ "8 x^5 + 6 x^4 + 12 x^3 + 8 x^2 + 4 x + 2" ] }, - "execution_count": 78, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } @@ -2597,7 +2628,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 80, "id": "81d433fc-6dcd-42a7-97ef-362913bf99c0", "metadata": {}, "outputs": [ @@ -2607,7 +2638,7 @@ "(2.0 x + 1.5, -2.0 x - 2.0)" ] }, - "execution_count": 79, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -2629,7 +2660,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 81, "id": "f1e28f9a-0366-44a7-9649-d4d2b74a9280", "metadata": {}, "outputs": [ @@ -2639,7 +2670,7 @@ "(2.0 x + 1.5, -2.0 x - 2.0)" ] }, - "execution_count": 80, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -2658,7 +2689,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 82, "id": "1377b01d-eded-4d0b-892c-75740cb3e8a8", "metadata": {}, "outputs": [ @@ -2668,7 +2699,7 @@ "2 + 2 x^2" ] }, - "execution_count": 81, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -2682,7 +2713,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 83, "id": "424c40e8-564e-4c64-b0f1-5122f6c7a41e", "metadata": {}, "outputs": [], @@ -2700,7 +2731,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 84, "id": "f8094d46-9ca8-46dc-9be3-96eb363b3ade", "metadata": {}, "outputs": [ @@ -2710,7 +2741,7 @@ "(2 x + 3/2, -2 x - 2)" ] }, - "execution_count": 83, + "execution_count": 84, "metadata": {}, "output_type": "execute_result" } @@ -2732,7 +2763,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 85, "id": "c121753b-dc2c-4000-9f14-b71b78f65d60", "metadata": {}, "outputs": [ @@ -2742,7 +2773,7 @@ "-2 x - 2" ] }, - "execution_count": 84, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -2762,7 +2793,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 86, "id": "f26253d7-43fd-4242-96ca-5032a309e48e", "metadata": {}, "outputs": [ @@ -2772,7 +2803,7 @@ "2" ] }, - "execution_count": 85, + "execution_count": 86, "metadata": {}, "output_type": "execute_result" } @@ -2791,7 +2822,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 87, "id": "1b33195a-0c3c-46c4-94b9-94c9ca0dee0e", "metadata": {}, "outputs": [ @@ -2801,7 +2832,7 @@ "4" ] }, - "execution_count": 86, + "execution_count": 87, "metadata": {}, "output_type": "execute_result" } @@ -2828,7 +2859,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 88, "id": "cf284301-bb0d-44dc-b3cf-51ef187b01ad", "metadata": {}, "outputs": [ @@ -2838,7 +2869,7 @@ "x^4 + x^2 + x + 1" ] }, - "execution_count": 87, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } @@ -2870,7 +2901,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 89, "id": "85ce3cb2-faf5-4a75-b624-dfff2b2ce255", "metadata": {}, "outputs": [ @@ -2880,7 +2911,7 @@ "141" ] }, - "execution_count": 88, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -2912,7 +2943,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 90, "id": "6abad578-adfe-4389-b4dc-865494102c6a", "metadata": {}, "outputs": [ @@ -2937,7 +2968,7 @@ "[ 0x8c, 0xa1, 0x89, 0xd, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0xf, 0xb0, 0x54, 0xbb, 0x16 ]" ] }, - "execution_count": 89, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } @@ -2987,7 +3018,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 91, "id": "763cab51-af5d-423d-b8cf-f6436db1280a", "metadata": {}, "outputs": [ @@ -2997,7 +3028,7 @@ "- x + 1" ] }, - "execution_count": 90, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -3027,7 +3058,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 92, "id": "3e8b7f54-ea20-44ce-a0d3-e9cb6d7ef54b", "metadata": {}, "outputs": [ @@ -3044,7 +3075,7 @@ "False" ] }, - "execution_count": 91, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } @@ -3078,7 +3109,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 93, "id": "728c317c-4f71-4a23-bdad-2a0f8f43c60d", "metadata": {}, "outputs": [ @@ -3088,7 +3119,7 @@ "True" ] }, - "execution_count": 92, + "execution_count": 93, "metadata": {}, "output_type": "execute_result" } @@ -3110,7 +3141,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 94, "id": "99fed470-0bbb-4975-a391-c6d755a9a635", "metadata": {}, "outputs": [ @@ -3120,7 +3151,7 @@ "30" ] }, - "execution_count": 93, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -3147,7 +3178,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 95, "id": "284175c0-2153-4d71-9488-c6a902abfde4", "metadata": {}, "outputs": [ @@ -3216,7 +3247,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 96, "id": "e6829610-8540-4ff3-9011-fe29a5397ca8", "metadata": {}, "outputs": [ @@ -3307,7 +3338,7 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 97, "id": "8d4c4b43-e593-407a-92f8-86b653a09c8a", "metadata": {}, "outputs": [ @@ -3382,7 +3413,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 98, "id": "143fbfa9-37f0-46a5-88e8-77881d3d9092", "metadata": {}, "outputs": [ @@ -3392,7 +3423,7 @@ "x^256 + 1" ] }, - "execution_count": 97, + "execution_count": 98, "metadata": {}, "output_type": "execute_result" } @@ -3418,7 +3449,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 99, "id": "703e1f66-401d-40be-a0f9-d3f08ced2b14", "metadata": {}, "outputs": [ @@ -3428,7 +3459,7 @@ "-1" ] }, - "execution_count": 98, + "execution_count": 99, "metadata": {}, "output_type": "execute_result" } @@ -3449,7 +3480,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 100, "id": "84d4ef9e-1484-48c8-b5a8-75a00f178c72", "metadata": {}, "outputs": [ @@ -3459,7 +3490,7 @@ "6 x^5 + 5 x^4 + 4 x^3 + 3 x^2 + 2 x + 1" ] }, - "execution_count": 99, + "execution_count": 100, "metadata": {}, "output_type": "execute_result" } @@ -3501,7 +3532,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 101, "id": "9b566550-f23c-4fbc-8b7c-63bbee8e0c72", "metadata": {}, "outputs": [ @@ -3540,7 +3571,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 102, "id": "55c29e0c-e0c2-409a-af23-6590fd9cc545", "metadata": {}, "outputs": [ @@ -3550,7 +3581,7 @@ "(113, 91)" ] }, - "execution_count": 101, + "execution_count": 102, "metadata": {}, "output_type": "execute_result" } @@ -3572,7 +3603,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 103, "id": "f980a2d0-4413-4812-a73d-1bab72a744f3", "metadata": {}, "outputs": [ @@ -3582,7 +3613,7 @@ "True" ] }, - "execution_count": 102, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } @@ -3601,7 +3632,7 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 104, "id": "2a3d8e7d-71b3-4a93-b6cc-803f00432c56", "metadata": {}, "outputs": [ @@ -3611,7 +3642,7 @@ "129" ] }, - "execution_count": 103, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -3631,7 +3662,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 105, "id": "76d3b602-4903-4218-b34c-a39fbe392ad1", "metadata": {}, "outputs": [ @@ -3641,7 +3672,7 @@ "0" ] }, - "execution_count": 104, + "execution_count": 105, "metadata": {}, "output_type": "execute_result" } @@ -3660,7 +3691,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 106, "id": "bb93b5fc-99c9-4977-8299-9342b84e143d", "metadata": {}, "outputs": [], @@ -3680,7 +3711,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 107, "id": "41e18357-da42-4cd7-bd4e-1c3355f1c69d", "metadata": {}, "outputs": [], @@ -3705,7 +3736,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 108, "id": "af81d5f2-a524-4555-8e74-06a0c9a7ea08", "metadata": {}, "outputs": [ @@ -3716,7 +3747,7 @@ " 0x03449ef2ed30a8deb96e584a08c329adbf1be87ce40f1a0e7b4e86178682c41a9c)" ] }, - "execution_count": 107, + "execution_count": 108, "metadata": {}, "output_type": "execute_result" } diff --git a/kryptools/__init__.py b/kryptools/__init__.py index dfb8b41..d154bc4 100644 --- a/kryptools/__init__.py +++ b/kryptools/__init__.py @@ -8,7 +8,7 @@ __version__ = "0.9.10" __email__ = "Gerald.Teschl@univie.ac.at" -from .nt import egcd, cf, convergents, legendre_symbol, jacobi_symbol, sqrt_mod, euler_phi, carmichael_lambda, moebius_mu, order, crt +from .nt import egcd, cf, convergents, legendre_symbol, jacobi_symbol, sqrt_mod, euler_phi, carmichael_lambda, moebius_mu, is_carmichael_number, order, crt from .primes import sieve_eratosthenes, prime_pi, is_prime, next_prime, previous_prime, random_prime, random_strongprime, is_safeprime, random_safeprime, is_blumprime, random_blumprime, miller_rabin_test, lucas_test from .intfuncs import iroot, ilog, perfect_square, perfect_power, prime_power from .factor import factorint, divisors diff --git a/kryptools/nt.py b/kryptools/nt.py index 909118b..3833684 100644 --- a/kryptools/nt.py +++ b/kryptools/nt.py @@ -9,6 +9,7 @@ euler_phi(n) Euler phi function of n carmichael_lambda(n) Carmichael lambda function of n moebius_mu(n) Moebius function of n + is_carmichael_number(n) tests if a number is a Carmichael number order(a, n) oder of a in the multiplicative group Z_n^* crt([a1, a2, ...],[m1, m2, ...]) Chinese Remainder Theorem """ @@ -174,6 +175,15 @@ def moebius_mu(n: int) -> int: return -1 return 1 +def is_carmichael_number(n: int) -> bool: + """Tests if a number is a Carmichael number using Korselt's criterion.""" + if n < 561: + return False + factors = factorint(n) + if len(factors) == 1: # prime + return False + return max(factors.values()) == 1 and not any((n-1) % (p-1) for p in factors) + # Order in Z_p^* def order(a: int, n: int, factor=False) -> int: diff --git a/tests/test_nt.py b/tests/test_nt.py index 8baa01d..9a37480 100644 --- a/tests/test_nt.py +++ b/tests/test_nt.py @@ -3,7 +3,7 @@ from math import prod from fractions import Fraction from kryptools import sieve_eratosthenes, is_prime -from kryptools import crt, cf, convergents, legendre_symbol, jacobi_symbol, carmichael_lambda, euler_phi, moebius_mu +from kryptools import crt, cf, convergents, legendre_symbol, jacobi_symbol, carmichael_lambda, euler_phi, moebius_mu, is_carmichael_number seed(0) def test_crt(): @@ -68,5 +68,14 @@ def test_moebius_mu(): for n in range(1, len(OEIS_A008683)+1): assert moebius_mu(n) == OEIS_A008683[n - 1] +OEIS_A002997 = [ 561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, + 46657, 52633, 62745, 63973, 75361, 101101, 115921, 126217, 162401, 172081, 188461, + 252601, 278545, 294409, 314821, 334153, 340561, 399001, 410041, 449065, 488881, + 512461, 530881, 552721 ] +def test_is_carmichael_number(): + for n in range(OEIS_A002997[4]+2): + assert is_carmichael_number(n) == (n in OEIS_A002997) + for n in OEIS_A002997: + assert is_carmichael_number(n) == True diff --git a/tests/test_primes.py b/tests/test_primes.py index d40aba7..2b5def9 100644 --- a/tests/test_primes.py +++ b/tests/test_primes.py @@ -68,6 +68,8 @@ def test_is_prime(): def test_is_safeprime(): for n in range(OEIS_A000720[-1]+2): assert is_safeprime(n) == (n in OEIS_A005385) + for n in OEIS_A005385: + assert is_safeprime(n) == True OEIS_A014233 = [ 2047, 1373653, 25326001, 3215031751, 2152302898747, 3474749660383, 341550071728321, 341550071728321, 3825123056546413051, 3825123056546413051,