Вход Регистрация
Файл: playtox.tk/Tools/phpmyadmin/libraries/blowfish.php
Строк: 151
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * The Horde_Cipher_Blowfish:: class implements the Horde_Cipher interface
 * encryption data using the Blowfish algorithm.
 *
 * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Mike Cochrane <mike@graftonhall.co.nz>
 * @package Horde_Cipher
 */
class Horde_Cipher_blowfish
{
    
/**
     * Pi Array
     *
     * @var array
     */
    
protected $p = array(
            
0x243F6A880x85A308D30x13198A2E0x03707344,
            
0xA40938220x299F31D00x082EFA980xEC4E6C89,
            
0x452821E60x38D013770xBE5466CF0x34E90C6C,
            
0xC0AC29B70xC97C50DD0x3F84D5B50xB5470917,
            
0x9216D5D90x8979FB1B);

    
/**
     * S Box (s1)
     *
     * @var array
     */
    
protected $s1 = array(
            
0xD1310BA60x98DFB5AC0x2FFD72DB0xD01ADFB7,
            
0xB8E1AFED0x6A267E960xBA7C90450xF12C7F99,
            
0x24A199470xB3916CF70x0801F2E20x858EFC16,
            
0x636920D80x71574E690xA458FEA30xF4933D7E,
            
0x0D95748F0x728EB6580x718BCD580x82154AEE,
            
0x7B54A41D0xC25A59B50x9C30D5390x2AF26013,
            
0xC5D1B0230x286085F00xCA4179180xB8DB38EF,
            
0x8E79DCB00x603A180E0x6C9E0E8B0xB01E8A3E,
            
0xD71577C10xBD314B270x78AF2FDA0x55605C60,
            
0xE65525F30xAA55AB940x574898620x63E81440,
            
0x55CA396A0x2AAB10B60xB4CC5C340x1141E8CE,
            
0xA15486AF0x7C72E9930xB3EE14110x636FBC2A,
            
0x2BA9C55D0x741831F60xCE5C3E160x9B87931E,
            
0xAFD6BA330x6C24CF5C0x7A3253810x28958677,
            
0x3B8F48980x6B4BB9AF0xC4BFE81B0x66282193,
            
0x61D809CC0xFB21A9910x487CAC600x5DEC8032,
            
0xEF845D5D0xE98575B10xDC2623020xEB651B88,
            
0x23893E810xD396ACC50x0F6D6FF30x83F44239,
            
0x2E0B44820xA48420040x69C8F04A0x9E1F9B5E,
            
0x21C668420xF6E96C9A0x670C9C610xABD388F0,
            
0x6A51A0D20xD8542F680x960FA7280xAB5133A3,
            
0x6EEF0B6C0x137A3BE40xBA3BF0500x7EFB2A98,
            
0xA1F1651D0x39AF01760x66CA593E0x82430E88,
            
0x8CEE86190x456F9FB40x7D84A5C30x3B8B5EBE,
            
0xE06F75D80x85C120730x401A449F0x56C16AA6,
            
0x4ED3AA620x363F77060x1BFEDF720x429B023D,
            
0x37D0D7240xD00A12480xDB0FEAD30x49F1C09B,
            
0x075372C90x80991B7B0x25D479D80xF6E8DEF7,
            
0xE3FE501A0xB6794C3B0x976CE0BD0x04C006BA,
            
0xC1A94FB60x409F60C40x5E5C9EC20x196A2463,
            
0x68FB6FAF0x3E6C53B50x1339B2EB0x3B52EC6F,
            
0x6DFC511F0x9B30952C0xCC8145440xAF5EBD09,
            
0xBEE3D0040xDE334AFD0x660F28070x192E4BB3,
            
0xC0CBA8570x45C8740F0xD20B5F390xB9D3FBDB,
            
0x5579C0BD0x1A60320A0xD6A100C60x402C7279,
            
0x679F25FE0xFB1FA3CC0x8EA5E9F80xDB3222F8,
            
0x3C7516DF0xFD616B150x2F501EC80xAD0552AB,
            
0x323DB5FA0xFD2387600x53317B480x3E00DF82,
            
0x9E5C57BB0xCA6F8CA00x1A87562E0xDF1769DB,
            
0xD542A8F60x287EFFC30xAC6732C60x8C4F5573,
            
0x695B27B00xBBCA58C80xE1FFA35D0xB8F011A0,
            
0x10FA3D980xFD2183B80x4AFCB56C0x2DD1D35B,
            
0x9A53E4790xB6F845650xD28E49BC0x4BFB9790,
            
0xE1DDF2DA0xA4CB7E330x62FB13410xCEE4C6E8,
            
0xEF20CADA0x36774C010xD07E9EFE0x2BF11FB4,
            
0x95DBDA4D0xAE9091980xEAAD8E710x6B93D5A0,
            
0xD08ED1D00xAFC725E00x8E3C5B2F0x8E7594B7,
            
0x8FF6E2FB0xF2122B640x8888B8120x900DF01C,
            
0x4FAD5EA00x688FC31C0xD1CFF1910xB3A8C1AD,
            
0x2F2F22180xBE0E17770xEA752DFE0x8B021FA1,
            
0xE5A0CC0F0xB56F74E80x18ACF3D60xCE89E299,
            
0xB4A84FE00xFD13E0B70x7CC43B810xD2ADA8D9,
            
0x165FA2660x809577050x93CC73140x211A1477,
            
0xE6AD20650x77B5FA860xC75442F50xFB9D35CF,
            
0xEBCDAF0C0x7B3E89A00xD6411BD30xAE1E7E49,
            
0x00250E2D0x2071B35E0x226800BB0x57B8E0AF,
            
0x2464369B0xF009B91E0x5563911D0x59DFA6AA,
            
0x78C143890xD95A537F0x207D5BA20x02E5B9C5,
            
0x832603760x6295CFA90x11C819680x4E734A41,
            
0xB3472DCA0x7B14A94A0x1B5100520x9A532915,
            
0xD60F573F0xBC9BC6E40x2B60A4760x81E67400,
            
0x08BA6FB50x571BE91F0xF296EC6B0x2A0DD915,
            
0xB66365210xE7B9F9B60xFF34052E0xC5855664,
            
0x53B02D5D0xA99F8FA10x08BA47990x6E85076A);

    
/**
     * S Box (s2)
     *
     * @var array
     */
    
protected $s2 = array(
            
0x4B7A70E90xB5B329440xDB75092E0xC4192623,
            
0xAD6EA6B00x49A7DF7D0x9CEE60B80x8FEDB266,
            
0xECAA8C710x699A17FF0x5664526C0xC2B19EE1,
            
0x193602A50x75094C290xA05913400xE4183A3E,
            
0x3F54989A0x5B429D650x6B8FE4D60x99F73FD6,
            
0xA1D29C070xEFE830F50x4D2D38E60xF0255DC1,
            
0x4CDD20860x8470EB260x6382E9C60x021ECC5E,
            
0x09686B3F0x3EBAEFC90x3C9718140x6B6A70A1,
            
0x687F35840x52A0E2860xB79C53050xAA500737,
            
0x3E07841C0x7FDEAE5C0x8E7D44EC0x5716F2B8,
            
0xB03ADA370xF0500C0D0xF01C1F040x0200B3FF,
            
0xAE0CF51A0x3CB574B20x25837A580xDC0921BD,
            
0xD19113F90x7CA92FF60x943247730x22F54701,
            
0x3AE5E5810x37C2DADC0xC8B576340x9AF3DDA7,
            
0xA94461460x0FD0030E0xECC8C73E0xA4751E41,
            
0xE238CD990x3BEA0E2F0x3280BBA10x183EB331,
            
0x4E548B380x4F6DB9080x6F420D030xF60A04BF,
            
0x2CB812900x24977C790x5679B0720xBCAF89AF,
            
0xDE9A771F0xD99308100xB38BAE120xDCCF3F2E,
            
0x5512721F0x2E6B71240x501ADDE60x9F84CD87,
            
0x7A5847180x7408DA170xBC9F9ABC0xE94B7D8C,
            
0xEC7AEC3A0xDB851DFA0x630943660xC464C3D2,
            
0xEF1C18470x3215D9080xDD433B370x24C2BA16,
            
0x12A14D430x2A65C4510x509400020x133AE4DD,
            
0x71DFF89E0x10314E550x81AC77D60x5F11199B,
            
0x043556F10xD7A3C76B0x3C11183B0x5924A509,
            
0xF28FE6ED0x97F1FBFA0x9EBABF2C0x1E153C6E,
            
0x86E345700xEAE96FB10x860E5E0A0x5A3E2AB3,
            
0x771FE71C0x4E3D06FA0x2965DCB90x99E71D0F,
            
0x803E89D60x5266C8250x2E4CC9780x9C10B36A,
            
0xC6150EBA0x94E2EA780xA5FC3C530x1E0A2DF4,
            
0xF2F74EA70x361D2B3D0x1939260F0x19C27960,
            
0x5223A7080xF71312B60xEBADFE6E0xEAC31F66,
            
0xE3BC45950xA67BC8830xB17F37D10x018CFF28,
            
0xC332DDEF0xBE6C5AA50x655821850x68AB9802,
            
0xEECEA50F0xDB2F953B0x2AEF7DAD0x5B6E2F84,
            
0x1521B6280x290761700xECDD47750x619F1510,
            
0x13CCA8300xEB61BD960x0334FE1E0xAA0363CF,
            
0xB5735C900x4C70A2390xD59E9E0B0xCBAADE14,
            
0xEECC86BC0x60622CA70x9CAB5CAB0xB2F3846E,
            
0x648B1EAF0x19BDF0CA0xA02369B90x655ABB50,
            
0x40685A320x3C2AB4B30x319EE9D50xC021B8F7,
            
0x9B540B190x875FA0990x95F7997E0x623D7DA8,
            
0xF837889A0x97E32D770x11ED935F0x16681281,
            
0x0E3588290xC7E61FD60x96DEDFA10x7858BA99,
            
0x57F584A50x1B2272630x9B83C3FF0x1AC24696,
            
0xCDB30AEB0x532E30540x8FD948E40x6DBC3128,
            
0x58EBF2EF0x34C6FFEA0xFE28ED610xEE7C3C73,
            
0x5D4A14D90xE864B7E30x42105D140x203E13E0,
            
0x45EEE2B60xA3AAABEA0xDB6C4F150xFACB4FD0,
            
0xC742F4420xEF6ABBB50x654F3B1D0x41CD2105,
            
0xD81E799E0x86854DC70xE44B476A0x3D816250,
            
0xCF62A1F20x5B8D26460xFC8883A00xC1C7B6A3,
            
0x7F1524C30x69CB74920x47848A0B0x5692B285,
            
0x095BBF000xAD19489D0x1462B1740x23820E00,
            
0x58428D2A0x0C55F5EA0x1DADF43E0x233F7061,
            
0x3372F0920x8D937E410xD65FECF10x6C223BDB,
            
0x7CDE37590xCBEE74600x4085F2A70xCE77326E,
            
0xA60780840x19F8509E0xE8EFD8550x61D99735,
            
0xA969A7AA0xC50C06C20x5A04ABFC0x800BCADC,
            
0x9E447A2E0xC34534840xFDD567050x0E1E9EC9,
            
0xDB73DBD30x105588CD0x675FDA790xE3674340,
            
0xC5C434650x713E38D80x3D28F89E0xF16DFF20,
            
0x153E21E70x8FB03D4A0xE6E39F2B0xDB83ADF7);

    
/**
     * S Box (s3)
     *
     * @var array
     */
    
protected $s3 = array(
            
0xE93D5A680x948140F70xF64C261C0x94692934,
            
0x411520F70x7602D4F70xBCF46B2E0xD4A20068,
            
0xD40824710x3320F46A0x43B7D4B70x500061AF,
            
0x1E39F62E0x972445460x14214F740xBF8B8840,
            
0x4D95FC1D0x96B591AF0x70F4DDD30x66A02F45,
            
0xBFBC09EC0x03BD97850x7FAC6DD00x31CB8504,
            
0x96EB27B30x55FD39410xDA2547E60xABCA0A9A,
            
0x285078250x530429F40x0A2C86DA0xE9B66DFB,
            
0x68DC14620xD74869000x680EC0A40x27A18DEE,
            
0x4F3FFEA20xE887AD8C0xB58CE0060x7AF4D6B6,
            
0xAACE1E7C0xD3375FEC0xCE78A3990x406B2A42,
            
0x20FE9E350xD9F385B90xEE39D7AB0x3B124E8B,
            
0x1DC9FAF70x4B6D18560x26A366310xEAE397B2,
            
0x3A6EFA740xDD5B43320x6841E7F70xCA7820FB,
            
0xFB0AF54E0xD8FEB3970x454056AC0xBA489527,
            
0x55533A3A0x20838D870xFE6BA9B70xD096954B,
            
0x55A867BC0xA1159A580xCCA929630x99E1DB33,
            
0xA62A4A560x3F3125F90x5EF47E1C0x9029317C,
            
0xFDF8E8020x04272F700x80BB155C0x05282CE3,
            
0x95C115480xE4C66D220x48C1133F0xC70F86DC,
            
0x07F9C9EE0x41041F0F0x404779A40x5D886E17,
            
0x325F51EB0xD59BC0D10xF2BCC18F0x41113564,
            
0x257B78340x602A9C600xDFF8E8A30x1F636C1B,
            
0x0E12B4C20x02E1329E0xAF664FD10xCAD18115,
            
0x6B2395E00x333E92E10x3B240B620xEEBEB922,
            
0x85B2A20E0xE6BA0D990xDE720C8C0x2DA2F728,
            
0xD01278450x95B794FD0x647D08620xE7CCF5F0,
            
0x5449A36F0x877D48FA0xC39DFD270xF33E8D1E,
            
0x0A4763410x992EFF740x3A6F6EAB0xF4F8FD37,
            
0xA812DC600xA1EBDDF80x991BE14C0xDB6E6B0D,
            
0xC67B55100x6D672C370x2765D43B0xDCD0E804,
            
0xF1290DC70xCC00FFA30xB5390F920x690FED0B,
            
0x667B9FFB0xCEDB7D9C0xA091CF0B0xD9155EA3,
            
0xBB132F880x515BAD240x7B9479BF0x763BD6EB,
            
0x37392EB30xCC1159790x8026E2970xF42E312D,
            
0x6842ADA70xC66A2B3B0x12754CCC0x782EF11C,
            
0x6A1242370xB79251E70x06A1BBE60x4BFB6350,
            
0x1A6B10180x11CAEDFA0x3D25BDD80xE2E1C3C9,
            
0x444216590x0A1213860xD90CEC6E0xD5ABEA2A,
            
0x64AF674E0xDA86A85F0xBEBFE9880x64E4C3FE,
            
0x9DBC80570xF0F7C0860x60787BF80x6003604D,
            
0xD1FD83460xF6381FB00x7745AE040xD736FCCC,
            
0x83426B330xF01EAB710xB08041870x3C005E5F,
            
0x77A057BE0xBDE8AE240x554642990xBF582E61,
            
0x4E58F48F0xF2DDFDA20xF474EF380x8789BDC2,
            
0x5366F9C30xC8B38E740xB475F2550x46FCD9B9,
            
0x7AEB26610x8B1DDF840x846A0E790x915F95E2,
            
0x466E598E0x20B457700x8CD555910xC902DE4C,
            
0xB90BACE10xBB8205D00x11A862480x7574A99E,
            
0xB77F19B60xE0A9DC090x662D09A10xC4324633,
            
0xE85A1F020x09F0BE8C0x4A99A0250x1D6EFE10,
            
0x1AB93D1D0x0BA5A4DF0xA186F20F0x2868F169,
            
0xDCB7DA830x573906FE0xA1E2CE9B0x4FCD7F52,
            
0x50115E010xA70683FA0xA002B5C40x0DE6D027,
            
0x9AF88C270x773F86410xC3604C060x61A806B5,
            
0xF0177A280xC0F586E00x006058AA0x30DC7D62,
            
0x11E69ED70x2338EA630x53C2DD940xC2C21634,
            
0xBBCBEE560x90BCB6DE0xEBFC7DA10xCE591D76,
            
0x6F05E4090x4B7C01880x39720A3D0x7C927C24,
            
0x86E3725F0x724D9DB90x1AC15BB40xD39EB8FC,
            
0xED5455780x08FCA5B50xD83D7CD30x4DAD0FC4,
            
0x1E50EF5E0xB161E6F80xA28514D90x6C51133C,
            
0x6FD5C7E70x56E14EC40x362ABFCE0xDDC6C837,
            
0xD79A32340x926382120x670EFA8E0x406000E0);

    
/**
     * S Box (s4)
     *
     * @var array
     */
    
protected $s4 = array(
            
0x3A39CE370xD3FAF5CF0xABC277370x5AC52D1B,
            
0x5CB0679E0x4FA337420xD38227400x99BC9BBE,
            
0xD5118E9D0xBF0F73150xD62D1C7E0xC700C47B,
            
0xB78C1B6B0x21A190450xB26EB1BE0x6A366EB4,
            
0x5748AB2F0xBC946E790xC6A376D20x6549C2C8,
            
0x530FF8EE0x468DDE7D0xD5730A1D0x4CD04DC6,
            
0x2939BBDB0xA9BA46500xAC9526E80xBE5EE304,
            
0xA1FAD5F00x6A2D519A0x63EF8CE20x9A86EE22,
            
0xC089C2B80x43242EF60xA51E03AA0x9CF2D0A4,
            
0x83C061BA0x9BE96A4D0x8FE515500xBA645BD6,
            
0x2826A2F90xA73A3AE10x4BA995860xEF5562E9,
            
0xC72FEFD30xF752F7DA0x3F046F690x77FA0A59,
            
0x80E4A9150x87B086010x9B09E6AD0x3B3EE593,
            
0xE990FD5A0x9E34D7970x2CF0B7D90x022B8B51,
            
0x96D5AC3A0x017DA67D0xD1CF3ED60x7C7D2D28,
            
0x1F9F25CF0xADF2B89B0x5AD6B4720x5A88F54C,
            
0xE029AC710xE019A5E60x47B0ACFD0xED93FA9B,
            
0xE8D3C48D0x283B57CC0xF8D566290x79132E28,
            
0x785F01910xED7560550xF7960E440xE3D35E8C,
            
0x15056DD40x88F46DBA0x03A161250x0564F0BD,
            
0xC3EB9E150x3C9057A20x97271AEC0xA93A072A,
            
0x1B3F6D9B0x1E6321F50xF59C66FB0x26DCF319,
            
0x7533D9280xB155FDF50x035634820x8ABA3CBB,
            
0x285177110xC20AD9F80xABCC51670xCCAD925F,
            
0x4DE817510x3830DC8E0x379D58620x9320F991,
            
0xEA7A90C20xFB3E7BCE0x5121CE640x774FBE32,
            
0xA8B6E37E0xC3293D460x48DE53690x6413E680,
            
0xA2AE08100xDD6DB2240x69852DFD0x09072166,
            
0xB39A460A0x6445C0DD0x586CDECF0x1C20C8AE,
            
0x5BBEF7DD0x1B588D400xCCD2017F0x6BB4E3BB,
            
0xDDA26A7E0x3A59FF450x3E350A440xBCB4CDD5,
            
0x72EACEA80xFA6484BB0x8D6612AE0xBF3C6F47,
            
0xD29BE4630x542F5D9E0xAEC2771B0xF64E6370,
            
0x740E0D8D0xE75B13570xF87216710xAF537D5D,
            
0x4040CB080x4EB4E2CC0x34D2466A0x0115AF84,
            
0xE1B004280x95983A1D0x06B89FB40xCE6EA048,
            
0x6F3F3B820x3520AB820x011A1D4B0x277227F8,
            
0x611560B10xE7933FDC0xBB3A792B0x344525BD,
            
0xA08839E10x51CE794B0x2F32C9B70xA01FBAC9,
            
0xE01CC87E0xBCC7D1F60xCF0111C30xA1E8AAC7,
            
0x1A9087490xD44FBD9A0xD0DADECB0xD50ADA38,
            
0x0339C32A0xC69136670x8DF9317C0xE0B12B4F,
            
0xF79E59B70x43F5BB3A0xF2D519FF0x27D9459C,
            
0xBF97222C0x15E6FC2A0x0F91FC710x9B941525,
            
0xFAE593610xCEB69CEB0xC2A864590x12BAA8D1,
            
0xB6C1075E0xE3056A0C0x10D250650xCB03A442,
            
0xE0EC6E0E0x1698DB3B0x4C98A0BE0x3278E964,
            
0x9F1F95320xE0D392DF0xD3A0342B0x8971F21E,
            
0x1B0A74410x4BA3348C0xC5BE71200xC37632D8,
            
0xDF359F8D0x9B992F2E0xE60B6F470x0FE3F11D,
            
0xE54CDA540x1EDAD8910xCE6279CF0xCD3E7E6F,
            
0x1618B1660xFD2C1D050x848FD2C50xF6FB2299,
            
0xF523F3570xA63276230x93A835310x56CCCD02,
            
0xACF081620x5A75EBB50x6E1636970x88D273CC,
            
0xDE9662920x81B949D00x4C50901B0x71C65614,
            
0xE6C6C7BD0x327A140A0x45E1D0060xC3F27B9A,
            
0xC9AA53FD0x62A80F000xBB25BFE20x35BDD2F6,
            
0x711269050xB20402220xB6CBCF7C0xCD769C2B,
            
0x53113EC00x1640E3D30x38ABBD600x2547ADF0,
            
0xBA38209C0xF746CE760x77AFA1C50x20756060,
            
0x85CBFE4E0x8AE88DD80x7AAAF9B00x4CF9AA7E,
            
0x1948C25C0x02FB8A8C0x01C36AE40xD6EBE1F9,
            
0x90D4F8690xA65CDEA00x3F09252D0xC208E69F,
            
0xB74E61320xCE77E25B0x578FDFE30x3AC372E6);

    
/**
     * The number of rounds to do
     *
     * @var integer
     */
    
protected $_rounds 16;

    
/**
     * Set the key to be used for en/decryption.
     *
     * @param string $key  The key to use.
     * @return bool
     */
    
public function setKey($key)
    {
        
$key array_values(unpack('C*'$key));
        
$keyLen count($key);
        if (
$keyLen == 0) {
            return 
false;
        }

        
$keyPos $keyXor 0;
        for (
$i 0$iMax count($this->p); $i $iMax; ++$i) {
            for (
$t 0$t 4$t++) {
                
$keyXor = ($keyXor << 8) | (($key[$keyPos]) & 0x0ff);
                if (++
$keyPos == $keyLen) {
                    
$keyPos 0;
                }
            }
            
$this->p[$i] = $this->p[$i] ^ $keyXor;
        }

        
$encZero = array('L' => 0'R' => 0);
        for (
$i 0$i $iMax$i += 2) {
          
$encZero $this->_encryptBlock($encZero['L'], $encZero['R']);
          
$this->p[$i] = $encZero['L'];
          
$this->p[$i 1] = $encZero['R'];
        }

        
$iMax count($this->s1);
        for (
$i 0$i $iMax$i += 2) {
          
$encZero $this->_encryptBlock($encZero['L'], $encZero['R']);
          
$this->s1[$i] = $encZero['L'];
          
$this->s1[$i 1] = $encZero['R'];
        }

        
$iMax count($this->s2);
        for (
$i 0$i $iMax$i += 2) {
          
$encZero $this->_encryptBlock($encZero['L'], $encZero['R']);
          
$this->s2[$i] = $encZero['L'];
          
$this->s2[$i 1] = $encZero['R'];
        }

        
$iMax count($this->s3);
        for (
$i 0$i $iMax$i += 2) {
          
$encZero $this->_encryptBlock($encZero['L'], $encZero['R']);
          
$this->s3[$i] = $encZero['L'];
          
$this->s3[$i 1] = $encZero['R'];
        }

        
$iMax count($this->s4);
        for (
$i 0$i $iMax$i += 2) {
          
$encZero $this->_encryptBlock($encZero['L'], $encZero['R']);
          
$this->s4[$i] = $encZero['L'];
          
$this->s4[$i 1] = $encZero['R'];
        }
    }

    
/**
     * Encrypt a block of data.
     *
     * @param string $block      The data to encrypt.
     * @param string $key        The key to use.
     *
     * @return string  The encrypted output.
     */
    
public function encryptBlock($block$key null)
    {
        if (!
is_null($key)) {
            
$this->setKey($key);
        }

        list(
$L$R) = array_values(unpack('N*'$block));
        
$parts $this->_encryptBlock($L$R);
        return 
pack('NN'$parts['L'], $parts['R']);
    }

    
/**
     * Encrypt left and right halves of a block of data.
     *
     * @param integer $L  Left half of the data.
     * @param integer $R  Right half of the data.
     *
     * @return array  A hash, with keys 'L' and 'R', and the encrypted data as
     *                the values.
     */
    
protected function _encryptBlock($L$R)
    {
        
$L ^= $this->p[0];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[1];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[2];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[3];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[4];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[5];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[6];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[7];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[8];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[9];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[10];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[11];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[12];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[13];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[14];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[15];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[16];
        
$R ^= $this->p[17];

        return array(
'L' => $R'R' => $L);
    }

    
/**
     * Decrypt a block of data.
     *
     * @param string $block  The data to decrypt.
     * @param string $key    The key to use.
     *
     * @return string  The decrypted output.
     */
    
public function decryptBlock($block$key null)
    {
        if (!
is_null($key)) {
            
$this->setKey($key);
        }

// change for phpMyAdmin
        
$L null;
        
$R null;

        
$retarray array_values(unpack('N*'$block));
        if (isset(
$retarray[0])) {
            
$L $retarray[0];
        }
        if (isset(
$retarray[1])) {
            
$R $retarray[1];
        }
// end change for phpMyAdmin

        
$L ^= $this->p[17];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[16];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[15];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[14];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[13];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[12];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[11];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[10];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[9];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[8];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[7];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[6];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[5];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[4];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[3];
        
$R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L 0x0ff]) ^ $this->p[2];
        
$L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R 0x0ff]) ^ $this->p[1];

        return 
pack("NN"$R $this->p[0], $L);
    }

}

// higher-level functions:
/**
 * Encryption using blowfish algorithm
 *
 * @param string  original data
 * @param string  the secret
 *
 * @return  string  the encrypted result
 *
 * @access  public
 *
 */
function PMA_blowfish_encrypt($data$secret)
{
    
$pma_cipher = new Horde_Cipher_blowfish;
    
$encrypt '';

    
$mod strlen($data) % 8;

    if (
$mod 0) {
        
$data .= str_repeat(""$mod);
    }

    foreach (
str_split($data8) as $chunk) {
        
$encrypt .= $pma_cipher->encryptBlock($chunk$secret);
    }
    return 
base64_encode($encrypt);
}

/**
 * Decryption using blowfish algorithm
 *
 * @param string  encrypted data
 * @param string  the secret
 *
 * @return  string  original data
 *
 * @access  public
 *
 */
function PMA_blowfish_decrypt($encdata$secret)
{
    
$pma_cipher = new Horde_Cipher_blowfish;
    
$decrypt '';
    
$data base64_decode($encdata);

    foreach (
str_split($data8) as $chunk) {
        
$decrypt .= $pma_cipher->decryptBlock($chunk$secret);
    }
    return 
trim($decrypt);
}

?>
Онлайн: 0
Реклама