This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Strongly Encrypting Data
CodeExpectedActual
require 'rubygems'
require 'ezcrypto'
plaintext = '24.9195N 17.821E'
ezcrypto_key = EzCrypto::Key.with_password 'My secret key', 'salt string'
ezcrypto_ciphertext = ezcrypto_key.encrypt(plaintext)
"F\262\260\273\217\tR\351\362-\021-a\336\324Qc..." "F\262\260\273\217\tR\351\362-\021-a\336\324Qc\362\203?f\303e\310\324\320c\004\031\036\233\365"
ezcrypto_key.decrypt(ezcrypto_ciphertext)
"24.9195N 17.821E" "24.9195N 17.821E"
require 'crypt/rijndael'
aes_key = Crypt::Rijndael.new('My secret key')
aes_cyphertext = aes_key.encrypt_string(plaintext)
"\e\003\203\030]\203\t\346..." "iI\276\247\v\202\367\2202\256\\2+\021xG\016\226\304\270\217\265,\226L\273c4\325\202\231\234U\255\324\270\374\253\234\253\300b\231Ff\271\377L"
aes_key.decrypt_string(aes_cyphertext)
"24.9195N 17.821E" "24.9195N 17.821E"
blowfish_key = EzCrypto::Key.with_password('My secret password', 'salt string',
                                           :algorithm=>'blowfish')
Crypt example
require 'crypt/blowfish'
blowfish_key = Crypt::Blowfish.new('My secret password')
#<Crypt::Blowfish:0xb790b074 @pArray=[840023612, 530446302, 1411491428, 4081829320, 1231673980, 1181973587, 2584525499, 773120608, 1338474503, 3273341622, 1282852618, 3499267758, 1387050530, 1645883166, 1517216670, 405155223, 2360120450, 4112130607], @key="My secret password", @sBoxes=[[2203236098, 766300952, 156191173, 1882022310, 4057543041, 3485437184, 304187826, 3163656264, 3250994635, 1213340871, 3019995183, 3297469655, 735482294, 2840248797, 783045065, 4181643748, 4054077585, 4292210231, 3470955999, 3943625613, 1454387457, 1404366809, 263180791, 4052394417, 159312749, 3485093577, 2310962829, 3642426881, 2032531642, 2336865194, 3709778076, 4134363305, 3435948027, 3924495836, 3507286964, 1768438041, 3519310056, 545769401, 344105197, 3001643609, 1695269385, 744914509, 2456501760, 3176694803, 3919154013, 3492720828, 4197401276, 3655142609, 477249936, 3153786655, 883074778, 4017401731, 1660329640, 3045272213, 575279439, 4023531073, 3427965208, 157401340, 531830493, 3668380719, 3028421202, 2382541668, 1174863674, 4291006987, 396257230, 1840017645, 3555464983, 118807454, 426740983, 2123192941, 4192915928, 2368172291, 491707409, 1069795305, 2885394596, 2113412579, 3862830556, 4117287839, 1939798754, 3974074206, 210955466, 2235138811, 3555282836, 3387336231, 1466484063, 2462033935, 3542378925, 2706079289, 2727526003, 3660298874, 2409781806, 1508091446, 3758884355, 1364558813, 3170042517, 4235141130, 4008795583, 1861688597, 3546493049, 113875885, 771287577, 211899578, 598875368, 1194641852, 1755901078, 2936768721, 3805364275, 4229804068, 1880433064, 414235437, 1432786352, 1198311665, 3409297669, 3473393270, 3071551626, 2740975747, 1948845099, 2847270122, 3418468968, 288086627, 3845920126, 2309045379, 3685839585, 3441382837, 2145052243, 1176155788, 2096734934, 3116152699, 4182507337, 330374439, 914721079, 2149063518, 656179746, 1341084958, 3141772440, 3533600797, 2276001301, 4253188141, 2045683574, 3048863080, 2259834492, 76212690, 3520693911, 3284713101, 1857478533, 3149838797, 933092753, 3183936159, 857256251, 2343113467, 2815225347, 1884531768, 2420626744, 3516946845, 1070217744, 300519515, 1657800056, 1948194570, 3445486152, 2469048022, 969660727, 2087361536, 4262761817, 3645629706, 138022016, 3571630914, 3452625687, 2491666265, 1506297593, 1051611551, 303494782, 620065652, 3368566469, 2811215135, 1863105100, 1991326275, 4197619230, 1625106464, 2067196004, 1249370643, 2926634106, 2094821363, 1605473858, 3171135686, 2204482936, 3643274074, 3847597494, 806487147, 273827290, 3915841177, 2509272452, 3266568623, 2492729006, 1031896611, 3397652094, 1100389123, 279505303, 3499856156, 933539288, 1654119968, 565600468, 2464087572, 2532772299, 268084809, 2736278799, 1830294583, 4023151165, 283748286, 3844545542, 2568733811, 3030409222, 1151853532, 2605764687, 1331501650, 2334776634, 672398007, 4120970374, 681812678, 3123556469, 3574568684, 50722147, 3567207336, 1214178593, 3897410228, 2030315598, 1639899941, 3660552875, 1948989015, 1579267736, 165810640, 1723144413, 177384145, 436052611, 3250028987, 3751354503, 1574260958, 192065705, 3759510770, 2230547052, 3876354545, 953249941, 2681297823, 3346087628, 4101297640, 3387135356, 3440275682, 274187658, 2285376679, 862955477, 3621334185, 1080643153, 3546356397, 226198564, 2214747787, 1042066485, 3419420154], [537907521, 1597923362, 3985476526, 4059543229, 2038742498, 994995458, 3661122147, 3912755476, 4222780544, 3315356098, 3662982858, 3513848213, 2293565493, 2906273544, 3351613923, 2719570602, 931515952, 654138707, 3565932862, 2372206714, 1188635585, 77739595, 205661953, 1177435543, 2697348923, 3329508333, 2229798267, 4274758804, 3485753915, 3048031601, 3028543864, 1899288908, 1652775339, 3135987801, 4108568397, 1488269514, 2944611010, 3939857368, 3864121757, 1196460618, 1185209564, 2784640395, 1087010134, 1037917049, 279241355, 307330636, 1431356232, 1041970258, 3460546729, 4033352046, 644212368, 1590426238, 433310405, 3679501961, 1053452285, 636686744, 1230842179, 482418324, 297033240, 4016295856, 2344952631, 2529009463, 3577764485, 2204819245, 2317915544, 3966513305, 4133477782, 3001185115, 4063094052, 3672134120, 3798395695, 2117732856, 605685388, 781892684, 2188483556, 4173521162, 2773094635, 1123656575, 516268490, 1800545184, 2627976352, 1182116890, 435779036, 4163086066, 1219742062, 1181575919, 4057526771, 2834871986, 2023899198, 2792509508, 3499559472, 3659433595, 3906783363, 628122194, 146605769, 3410572010, 4099540544, 3609216648, 2863833445, 2454345511, 4153395626, 1341287839, 2729103589, 826723929, 2725637089, 888313886, 2223721602, 156115216, 3637491889, 3807966169, 1874126441, 4174240240, 3924816836, 2887278510, 2515636769, 1878419788, 4155240332, 3086632869, 2164305169, 2106146411, 2816989902, 844938529, 222118720, 3713445593, 3704340047, 2831185485, 1599983906, 987543272, 2771307683, 2764546064, 2051140751, 2262971282, 3960945899, 3728193250, 107053317, 3848746501, 3306637316, 481479225, 688454819, 792662864, 2441677185, 2389942224, 411586505, 2762641886, 3278194570, 1812720742, 53334073, 3525349544, 2808224828, 3002253442, 3490408430, 539343633, 635588693, 3593352040, 2230659014, 767910902, 1030882455, 3852587564, 2724304990, 924655472, 1603614122, 3095627937, 375098335, 2485050621, 1300424239, 3072440971, 708966820, 1845000036, 82274750, 415583765, 1918397937, 2909277996, 1207971427, 1038566965, 499171790, 1694703213, 3286926673, 1319866316, 3289029053, 3472411172, 3934878813, 2741957221, 3475455621, 1973528939, 4026955880, 514122870, 1743596019, 4183833169, 1580393386, 3597668746, 3991572415, 3599313236, 1391358495, 2252323850, 411449260, 1527903102, 459098028, 805741093, 3731916308, 3357445764, 506327079, 4169524156, 551645884, 2856317988, 1537359345, 855123862, 4116454993, 1029932746, 609256146, 1497649912, 1836737615, 2432925167, 3255719479, 902756137, 1814557169, 676972026, 1684529327, 346625798, 1649026031, 3688387215, 3718449163, 2602969212, 2778488939, 3127258519, 3118781053, 92979337, 2867490371, 1910977332, 1632482363, 4141315645, 2902665244, 3104044486, 3034507586, 608100115, 3392372102, 2408720551, 3464723932, 4061883678, 1278736166, 2184833241, 18694834, 250735760, 2619925244, 3963962436, 204727702, 3153751480, 2460599150, 2101091712, 607423869, 208072310, 2815550701, 2696274493, 2369686328, 3976658776, 4014952374, 4055622180], [752657086, 1849445395, 2732367175, 2304074022, 1939693552, 1363192160, 138647057, 4071259463, 371328092, 666105740, 712462286, 121746875, 945739908, 1445907966, 1411880176, 1542100198, 953953397, 3433208862, 2948012905, 3471233444, 1596097237, 327489103, 20312962, 825679929, 3410178836, 425048580, 3776012237, 3737662328, 890522154, 958446123, 472437316, 4085993127, 316445540, 2933534787, 697475665, 3249532564, 368087971, 418635620, 3406276110, 3269980520, 3468574348, 821869071, 3733064476, 2974969055, 3764250574, 498729068, 4241181533, 2901009186, 1527610175, 351019860, 1043080110, 2502826131, 3077717158, 1008635618, 1632845584, 3595656054, 2936415812, 4204878220, 2960801228, 1997056582, 3786526155, 2273375936, 3171185136, 3717775386, 4244808604, 1112379905, 3155817415, 408546028, 122831710, 380278080, 4182618954, 3347085534, 958230063, 1443381395, 835704378, 1894135764, 1281161636, 3657441346, 3856971399, 90620015, 4122795010, 1424421830, 2792331560, 2603663969, 1229109395, 2996081364, 1522817370, 3973927142, 190958586, 3010053858, 2313667230, 4060433307, 3700202230, 66817003, 3663779927, 3601023946, 525721672, 1517468019, 4243125507, 3975963040, 2047718183, 1272200766, 1534146411, 2445896336, 2936675736, 990484465, 3651468549, 2790566148, 1336317478, 3455925855, 1863825912, 3678045083, 2322175342, 2205319281, 180108354, 3821489764, 776948033, 1874265632, 2728832656, 3220227590, 3812042224, 3648781340, 1128402536, 4187318465, 3300922416, 1638086167, 3007561092, 4142992959, 67073981, 3714024099, 1182052159, 2808086720, 1069885871, 3258018304, 3125523085, 2382520913, 1763674585, 3501116279, 562598745, 1533483293, 2921893483, 3484157626, 844286594, 3451263373, 158815500, 1928443562, 1898603865, 647355360, 4185603333, 1050955549, 3491449014, 2548163680, 3949128745, 489381696, 2826492580, 1757193976, 2312426196, 2957080178, 2778454448, 2164868009, 4244349340, 2714098902, 54084704, 1571269590, 2466939560, 1086748789, 3597746044, 3983927116, 4247756469, 2214028000, 2668165070, 3915555190, 2492700918, 2481222969, 2567443438, 3660592563, 3850714756, 4191649780, 1995470729, 1225611080, 771745857, 2219080623, 289298467, 534955180, 1983936107, 4205697534, 421703968, 2053156564, 237180957, 2081961352, 2919811529, 4021046003, 4170229952, 1794522593, 4009386615, 3260262315, 3773807213, 2232545101, 1355669123, 4277850664, 2605540260, 762367404, 530253323, 3099042426, 3221868667, 177290438, 662836722, 711171921, 1840904262, 4137628240, 1851978998, 3630683039, 164972214, 256840527, 2921210302, 2430147941, 947073320, 4215397793, 2037537396, 268471357, 1289715319, 3252348462, 3540454582, 3440669043, 1181588679, 4149963562, 1743934523, 3251356594, 1085627785, 3474350824, 1254128458, 1406197096, 1087024243, 1158794626, 200752999, 2182312116, 3427319257, 847752252, 1339316910, 3008748531, 4173443506, 3561581161, 1996721178, 425071813, 463823494, 652426958, 1938781350, 3659711259, 3604765038, 476795741, 2492530878, 2127497948, 1776913293, 3154892232, 3910653784, 3881812690], [4194945265, 1255852022, 3646598160, 1878033151, 2573694824, 42620493, 1346414842, 648390416, 1132595540, 1985259148, 3799436115, 288814624, 1034116371, 1363344230, 4265505896, 1456106642, 294225308, 1778237090, 3759922832, 372953224, 2859555882, 76126089, 3312028520, 2906684073, 2665124370, 1944052114, 2129521762, 1709601490, 3654154107, 1918987495, 429018300, 517804195, 642391219, 2994036126, 2305968929, 3370110930, 1459548251, 131093568, 31151308, 4075775313, 1623515191, 450029310, 198342126, 4147982578, 1869536672, 1737429242, 2135523421, 3608861409, 3971948153, 3082721102, 3970998033, 3281244331, 738625641, 1977725671, 650136671, 3277691044, 2563575313, 1788415387, 2959893242, 247231167, 1543122949, 1238664482, 3884678357, 365604434, 432291186, 1378205101, 3304054973, 4183255074, 485178034, 2336686584, 372956807, 4157623304, 4120429729, 2250795981, 3829730562, 2108193998, 4191657960, 735319331, 3561143364, 3102547213, 152764319, 1704347175, 57947845, 927203083, 851513630, 486609201, 3296736882, 3815063404, 3963909930, 1640877978, 3846773080, 113582222, 1338621558, 2780856784, 1002249153, 1016173632, 1019704636, 2972491138, 168709625, 2942598827, 301455956, 1160566027, 812370429, 3025270635, 2150042128, 3078587667, 2624570573, 207244693, 136723800, 2548762701, 1194971790, 409426451, 257057443, 4282967744, 108817992, 1082780004, 1715996930, 194474135, 3685147765, 854379657, 1605562960, 2737211137, 2028862993, 1392293394, 691176088, 3354060338, 2471156695, 1396073059, 3651359369, 445865148, 3447338032, 2309646422, 4083467891, 1977402273, 4119277609, 1650902585, 2320386651, 2336415688, 4022078208, 1933530500, 3446180732, 3470006375, 2026384786, 1333090816, 1367943246, 3761416094, 983362598, 3507934360, 1449739393, 3125079807, 3354696868, 2828835234, 676485439, 1074591943, 889668492, 3537079641, 4239009876, 3249752312, 667070631, 1898751313, 791516290, 1758960231, 3908051547, 1677889530, 2326138482, 3722943491, 3392090472, 2170801562, 1197232054, 2706103606, 2548252271, 3903979887, 2453823145, 1246545043, 1388836871, 1944433621, 3029476945, 2652316459, 1176670160, 3118506753, 2747950732, 2872269946, 790463161, 2874505490, 1017896702, 3563443867, 2249147590, 3611194680, 287682959, 3714712002, 2930782374, 1212971574, 2685986103, 3428128367, 2407960951, 4229473143, 3255095255, 4238520251, 2615609701, 63630413, 3772080447, 3835207816, 2568927003, 266330969, 97088916, 3994833202, 3870288407, 2017458426, 2380265041, 2479865973, 3216861248, 806804610, 244951079, 1684937940, 2009960745, 1977945367, 1672584423, 2760206911, 1481700562, 4060465207, 570570350, 2381612140, 3698894532, 1051546496, 242367428, 3125979401, 2980804181, 1031973505, 3907331211, 3849049249, 2950254954, 2011015529, 3909439821, 2031278110, 3377528669, 1456927636, 2735308633, 902944146, 697962565, 2266619979, 2789905275, 2942639563, 1616380960, 3328194255, 3002572058, 3363110134, 2765330482, 2345725212, 1391371121, 2624752292, 2443253851, 10380161, 148978682, 4187244366, 2048031474, 1773673113]]>