xref: /PHP-8.2/ext/hash/tests/fnv132.phpt (revision f8d79582)
1--TEST--
2Hash: FNV132 algorithm
3--FILE--
4<?php
5
6function R10($t) {
7    return str_repeat($t, 10);
8}
9
10function R500($t) {
11    return str_repeat($t, 500);
12}
13
14$tests = array(
15    array( "", "811c9dc5" ),
16    array( "a", "050c5d7e" ),
17    array( "b", "050c5d7d" ),
18    array( "c", "050c5d7c" ),
19    array( "d", "050c5d7b" ),
20    array( "e", "050c5d7a" ),
21    array( "f", "050c5d79" ),
22    array( "fo", "6b772514" ),
23    array( "foo", "408f5e13" ),
24    array( "foob", "b4b1178b" ),
25    array( "fooba", "fdc80fb0" ),
26    array( "foobar", "31f0b262" ),
27    array( "\0", "050c5d1f" ),
28    array( "a\0", "70772d5a" ),
29    array( "b\0", "6f772bc7" ),
30    array( "c\0", "6e772a34" ),
31    array( "d\0", "6d7728a1" ),
32    array( "e\0", "6c77270e" ),
33    array( "f\0", "6b77257b" ),
34    array( "fo\0", "408f5e7c" ),
35    array( "foo\0", "b4b117e9" ),
36    array( "foob\0", "fdc80fd1" ),
37    array( "fooba\0", "31f0b210" ),
38    array( "foobar\0", "ffe8d046" ),
39    array( "ch", "6e772a5c" ),
40    array( "cho", "4197aebb" ),
41    array( "chon", "fcc8100f" ),
42    array( "chong", "fdf147fa" ),
43    array( "chongo", "bcd44ee1" ),
44    array( "chongo ", "23382c13" ),
45    array( "chongo w", "846d619e" ),
46    array( "chongo wa", "1630abdb" ),
47    array( "chongo was", "c99e89b2" ),
48    array( "chongo was ", "1692c316" ),
49    array( "chongo was h", "9f091bca" ),
50    array( "chongo was he", "2556be9b" ),
51    array( "chongo was her", "628e0e73" ),
52    array( "chongo was here", "98a0bf6c" ),
53    array( "chongo was here!", "b10d5725" ),
54    array( "chongo was here!\n", "dd002f35" ),
55    array( "ch\0", "4197aed4" ),
56    array( "cho\0", "fcc81061" ),
57    array( "chon\0", "fdf1479d" ),
58    array( "chong\0", "bcd44e8e" ),
59    array( "chongo\0", "23382c33" ),
60    array( "chongo \0", "846d61e9" ),
61    array( "chongo w\0", "1630abba" ),
62    array( "chongo wa\0", "c99e89c1" ),
63    array( "chongo was\0", "1692c336" ),
64    array( "chongo was \0", "9f091ba2" ),
65    array( "chongo was h\0", "2556befe" ),
66    array( "chongo was he\0", "628e0e01" ),
67    array( "chongo was her\0", "98a0bf09" ),
68    array( "chongo was here\0", "b10d5704" ),
69    array( "chongo was here!\0", "dd002f3f" ),
70    array( "chongo was here!\n\0", "1c4a506f" ),
71    array( "cu", "6e772a41" ),
72    array( "cur", "26978421" ),
73    array( "curd", "e184ff97" ),
74    array( "curds", "9b5e5ac6" ),
75    array( "curds ", "5b88e592" ),
76    array( "curds a", "aa8164b7" ),
77    array( "curds an", "20b18c7b" ),
78    array( "curds and", "f28025c5" ),
79    array( "curds and ", "84bb753f" ),
80    array( "curds and w", "3219925a" ),
81    array( "curds and wh", "384163c6" ),
82    array( "curds and whe", "54f010d7" ),
83    array( "curds and whey", "8cea820c" ),
84    array( "curds and whey\n", "e12ab8ee" ),
85    array( "cu\0", "26978453" ),
86    array( "cur\0", "e184fff3" ),
87    array( "curd\0", "9b5e5ab5" ),
88    array( "curds\0", "5b88e5b2" ),
89    array( "curds \0", "aa8164d6" ),
90    array( "curds a\0", "20b18c15" ),
91    array( "curds an\0", "f28025a1" ),
92    array( "curds and\0", "84bb751f" ),
93    array( "curds and \0", "3219922d" ),
94    array( "curds and w\0", "384163ae" ),
95    array( "curds and wh\0", "54f010b2" ),
96    array( "curds and whe\0", "8cea8275" ),
97    array( "curds and whey\0", "e12ab8e4" ),
98    array( "curds and whey\n\0", "64411eaa" ),
99    array( "line 1\nline 2\nline 3", "31ae8f83" ),
100    array( "chongo <Landon Curt Noll> /\\../\\", "995fa9c4" ),
101    array( "chongo <Landon Curt Noll> /\\../\\\0", "35983f8c" ),
102    array( "chongo (Landon Curt Noll) /\\../\\", "5036a251" ),
103    array( "chongo (Landon Curt Noll) /\\../\\\0", "97018583" ),
104    array( "http://antwrp.gsfc.nasa.gov/apod/astropix.html", "b4448d60" ),
105    array( "http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash", "025dfe59" ),
106    array( "http://epod.usra.edu/", "c5eab3af" ),
107    array( "http://exoplanet.eu/", "7d21ba1e" ),
108    array( "http://hvo.wr.usgs.gov/cam3/", "7704cddb" ),
109    array( "http://hvo.wr.usgs.gov/cams/HMcam/", "d0071bfe" ),
110    array( "http://hvo.wr.usgs.gov/kilauea/update/deformation.html", "0ff3774c" ),
111    array( "http://hvo.wr.usgs.gov/kilauea/update/images.html", "b0fea0ea" ),
112    array( "http://hvo.wr.usgs.gov/kilauea/update/maps.html", "58177303" ),
113    array( "http://hvo.wr.usgs.gov/volcanowatch/current_issue.html", "4f599cda" ),
114    array( "http://neo.jpl.nasa.gov/risk/", "3e590a47" ),
115    array( "http://norvig.com/21-days.html", "965595f8" ),
116    array( "http://primes.utm.edu/curios/home.php", "c37f178d" ),
117    array( "http://slashdot.org/", "9711dd26" ),
118    array( "http://tux.wr.usgs.gov/Maps/155.25-19.5.html", "23c99b7f" ),
119    array( "http://volcano.wr.usgs.gov/kilaueastatus.php", "6e568b17" ),
120    array( "http://www.avo.alaska.edu/activity/Redoubt.php", "43f0245b" ),
121    array( "http://www.dilbert.com/fast/", "bcb7a001" ),
122    array( "http://www.fourmilab.ch/gravitation/orbits/", "12e6dffe" ),
123    array( "http://www.fpoa.net/", "0792f2d6" ),
124    array( "http://www.ioccc.org/index.html", "b966936b" ),
125    array( "http://www.isthe.com/cgi-bin/number.cgi", "46439ac5" ),
126    array( "http://www.isthe.com/chongo/bio.html", "728d49af" ),
127    array( "http://www.isthe.com/chongo/index.html", "d33745c9" ),
128    array( "http://www.isthe.com/chongo/src/calc/lucas-calc", "bc382a57" ),
129    array( "http://www.isthe.com/chongo/tech/astro/venus2004.html", "4bda1d31" ),
130    array( "http://www.isthe.com/chongo/tech/astro/vita.html", "ce35ccae" ),
131    array( "http://www.isthe.com/chongo/tech/comp/c/expert.html", "3b6eed94" ),
132    array( "http://www.isthe.com/chongo/tech/comp/calc/index.html", "445c9c58" ),
133    array( "http://www.isthe.com/chongo/tech/comp/fnv/index.html", "3db8bf9d" ),
134    array( "http://www.isthe.com/chongo/tech/math/number/howhigh.html", "2dee116d" ),
135    array( "http://www.isthe.com/chongo/tech/math/number/number.html", "c18738da" ),
136    array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html", "5b156176" ),
137    array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest", "2aa7d593" ),
138    array( "http://www.lavarnd.org/cgi-bin/corpspeak.cgi", "b2409658" ),
139    array( "http://www.lavarnd.org/cgi-bin/haiku.cgi", "e1489528" ),
140    array( "http://www.lavarnd.org/cgi-bin/rand-none.cgi", "fe1ee07e" ),
141    array( "http://www.lavarnd.org/cgi-bin/randdist.cgi", "e8842315" ),
142    array( "http://www.lavarnd.org/index.html", "3a6a63a2" ),
143    array( "http://www.lavarnd.org/what/nist-test.html", "06d2c18c" ),
144    array( "http://www.macosxhints.com/", "f8ef7225" ),
145    array( "http://www.mellis.com/", "843d3300" ),
146    array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm", "bb24f7ae" ),
147    array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm", "878c0ec9" ),
148    array( "http://www.paulnoll.com/", "b557810f" ),
149    array( "http://www.pepysdiary.com/", "57423246" ),
150    array( "http://www.sciencenews.org/index/home/activity/view", "87f7505e" ),
151    array( "http://www.skyandtelescope.com/", "bb809f20" ),
152    array( "http://www.sput.nl/~rob/sirius.html", "8932abb5" ),
153    array( "http://www.systemexperts.com/", "0a9b3aa0" ),
154    array( "http://www.tq-international.com/phpBB3/index.php", "b8682a24" ),
155    array( "http://www.travelquesttours.com/index.htm", "a7ac1c56" ),
156    array( "http://www.wunderground.com/global/stations/89606.html", "11409252" ),
157    array( R10("21701"), "a987f517" ),
158    array( R10("M21701"), "f309e7ed" ),
159    array( R10("2^21701-1"), "c9e8f417" ),
160    array( R10("\x54\xc5"), "7f447bdd" ),
161    array( R10("\xc5\x54"), "b929adc5" ),
162    array( R10("23209"), "57022879" ),
163    array( R10("M23209"), "dcfd2c49" ),
164    array( R10("2^23209-1"), "6edafff5" ),
165    array( R10("\x5a\xa9"), "f04fb1f1" ),
166    array( R10("\xa9\x5a"), "fb7de8b9" ),
167    array( R10("391581216093"), "c5f1d7e9" ),
168    array( R10("391581*2^216093-1"), "32c1f439" ),
169    array( R10("\x05\xf9\x9d\x03\x4c\x81"), "7fd3eb7d" ),
170    array( R10("FEDCBA9876543210"), "81597da5" ),
171    array( R10("\xfe\xdc\xba\x98\x76\x54\x32\x10"), "05eb7a25" ),
172    array( R10("EFCDAB8967452301"), "9c0fa1b5" ),
173    array( R10("\xef\xcd\xab\x89\x67\x45\x23\x01"), "53ccb1c5" ),
174    array( R10("0123456789ABCDEF"), "fabece15" ),
175    array( R10("\x01\x23\x45\x67\x89\xab\xcd\xef"), "4ad745a5" ),
176    array( R10("1032547698BADCFE"), "e5bdc495" ),
177    array( R10("\x10\x32\x54\x76\x98\xba\xdc\xfe"), "23b3c0a5" ),
178    array( R500("\x00"), "fa823dd5" ),
179    array( R500("\x07"), "0c6c58b9" ),
180    array( R500("~"), "e2dbccd5" ),
181    array( R500("\x7f"), "db7f50f9" ),
182);
183
184$i = 0;
185$pass = true;
186foreach($tests as $test) {
187    $result = hash('fnv132', $test[0]);
188    if ($result != $test[1]) {
189        echo "Iteration " . $i . " failed - expected '" . $test[1] . "', got '" . $result . "' for '" . $test[1] . "'\n";
190        $pass = false;
191    }
192    $i++;
193}
194
195if($pass) {
196    echo "PASS";
197}
198?>
199--EXPECT--
200PASS
201