Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

 
<% 'This is the NSA algorithm Skipjack 'according to: ' 'SKIPJACK and KEA Algorithm Specifications 'Version 2.0 '29 May 1998 'OFB operating mode ' 'More information concerning the algorithm 'can be found at: 'http://csrc.nist.gov/encryption/skipjack-kea.htm ' 'Skipjack is property of the NSA. ' 'EXAMPLE CALLS 'Decoded_Password = DeHex(OFB_Crypto(Encoded_Password, UserName)) 'Encoded_Password = OFB_Crypto(EnHex(Password), UserName) Dim F Dim K Dim key(131) Function OFB_Crypto(inp, IV) Dim i, Dat, Outp, old, OldDat For i = 1 To Len(inp) Step 16 Dat = Mid(inp, i, 16) If i = 1 Then old = Encrypt(IV) Else old = Encrypt(OldDat) End If OldDat = old Outp = Outp & CryptoXOR(Dat, old) Next OFB_Crypto = Outp End Function Function Encrypt(inp) Dim i, Counter, w1(32), w3(32), w4(32), w2(32) w1(0) = Mid(inp, 1, 4) w2(0) = Mid(inp, 5, 4) w3(0) = Mid(inp, 9, 4) w4(0) = Mid(inp, 13, 4) K = 0 Counter = 1 For i = 1 To 8 w1(K + 1) = BigXOR(BigXOR(G(w1(K), key), w4(K)), Hex(Counter)) w2(K + 1) = G(w1(K), key) w3(K + 1) = w2(K) w4(K + 1) = w3(K) Counter = Counter + 1 K = K + 1 Next For i = 1 To 8 w1(K + 1) = w4(K) w2(K + 1) = G(w1(K), key) w3(K + 1) = BigXOR(BigXOR(w1(K), w2(K)), Hex(Counter)) w4(K + 1) = w3(K) Counter = Counter + 1 K = K + 1 Next For i = 1 To 8 w1(K + 1) = BigXOR(BigXOR(G(w1(K), key), w4(K)), Hex(Counter)) w2(K + 1) = G(w1(K), key) w3(K + 1) = w2(K) w4(K + 1) = w3(K) Counter = Counter + 1 K = K + 1 Next For i = 1 To 8 w1(K + 1) = w4(K) w2(K + 1) = G(w1(K), key) w3(K + 1) = BigXOR(BigXOR(w1(K), w2(K)), Hex(Counter)) w4(K + 1) = w3(K) Counter = Counter + 1 K = K + 1 Next Encrypt = w1(32) & w2(32) & w3(32) & w4(32) End Function Function G(inp, key) Dim g1, g2, g3, g4, g5, g6, l g1 = Mid(inp, 1, 2) g2 = Mid(inp, 3, 2) l = F(CByte(BigTrans(BigXOR(g2, key(4 * K))))) g3 = BigXOR(l, g1) l = F(CByte(BigTrans(BigXOR(g3, key((4 * K) + 1))))) g4 = BigXOR(l, g2) l = F(CByte(BigTrans(BigXOR(g4, key((4 * K) + 2))))) g5 = BigXOR(l, g3) l = F(CByte(BigTrans(BigXOR(g5, key((4 * K) + 3))))) g6 = BigXOR(l, g4) l = g5 & g6 G = l End Function Function BigTrans(ByVal inp) Dim tempstr, tempnum, loopit, loopinner, o , i, Y, p, x inp = Right(inp, 8) tempstr = String(8 - Len(inp), "0") + inp inp = "" ' Convert to binary For loopit = 1 To 8 tempnum = Dec(Mid(tempstr, loopit, 1)) For loopinner = 3 To 0 Step -1 If tempnum And 2 ^ loopinner Then inp = inp + "1" Else inp = inp + "0" End If Next Next o = 0 For i = Len(inp) To 1 Step -1 If Mid(inp, i, 1) = "1" Then Y = 1 p = (Len(inp) - i) x = 2 Do While p > 0 Do While (p / 2) = (p \ 2) x = (x * x) Mod 255 p = p / 2 Loop Y = (x * Y) Mod 255 p = p - 1 Loop o = o + Y End If Next BigTrans = o End Function Function BigXOR(ByVal value1, ByVal value2) Dim valueans, loopit, tempnum tempnum = Len(value1) - Len(value2) If tempnum < 0 Then valueans = Left(value2, Abs(tempnum)) value2 = Mid(value2, Abs(tempnum) + 1) ElseIf tempnum > 0 Then valueans = Left(value1, Abs(tempnum)) value1 = Mid(value1, tempnum + 1) End If For loopit = 1 To Len(value1) valueans = valueans + Hex(Dec(Mid(value1, loopit, 1)) Xor Dec(Mid(value2, loopit, 1))) Next BigXOR = Right(valueans, 8) End Function Function CryptoXOR(ByVal value1, ByVal value2) Dim valueans, loopit, tempnum tempnum = Len(value1) - Len(value2) If tempnum < 0 Then valueans = Left(value2, Abs(tempnum)) value2 = Mid(value2, Abs(tempnum) + 1) ElseIf tempnum > 0 Then valueans = Left(value1, Abs(tempnum)) value1 = Mid(value1, tempnum + 1) End If For loopit = 1 To Len(value1) valueans = valueans + Hex(Dec(Mid(value1, loopit, 1)) Xor Dec(Mid(value2, loopit, 1))) Next CryptoXOR = Right(valueans, 16) End Function Function DeHex(inp) Dim i, x For i = 1 To Len(inp) Step 2 If Mid(inp, i, 2) <> 0 Then x = x & Chr(Dec(Mid(inp, i, 2))) End If Next DeHex = x End Function Function EnHex(x) Dim i, v, inp For i = 1 To Len(x) v = Hex(Asc(Mid(x, i, 1))) If Len(v) = 1 Then v = "0" & v inp = inp & v Next EnHex = inp End Function Function Init(Pass) F = Array("A3", "D7", "09", "83", "F8", "48", "F6", "F4", "B3", "21", "15", "78", "99", "B1", "AF", "F9", "E7", "2D", "4D", _ "8A", "CE", "4C", "CA", "2E", "52", "95", "D9", "1E", "4E", "38", "44", "28", "0A", "DF", "02", "A0", "17", "F1", _ "60", "68", "12", "B7", "7A", "C3", "E9", "FA", "3D", "53", "96", "84", "6B", "BA", "F2", "63", "9A", "19", "7C", _ "AE", "E5", "F5", "F7", "16", "6A", "A2", "39", "B6", "7B", "0F", "C1", "93", "81", "1B", "EE", "B4", "1A", "EA", _ "D0", "91", "2F", "B8", "55", "B9", "DA", "85", "3F", "41", "BF", "E0", "5A", "58", "80", "5F", "66", "0B", "D8", _ "90", "35", "D5", "C0", "A7", "33", "06", "65", "69", "45", "00", "94", "56", "6D", "98", "9B", "76", "97", "FC", _ "B2", "C2", "B0", "FE", "DB", "20", "E1", "EB", "D6", "E4", "DD", "47", "4A", "1D", "42", "ED", "9E", "6E", "49", _ "3C", "CD", "43", "27", "D2", "07", "D4", "DE", "C7", "67", "18", "89", "CB", "30", "1F", "8D", "C6", "8F", "AA", _ "C8", "74", "DC", "C9", "5D", "5C", "31", "A4", "70", "88", "61", "2C", "9F", "0D", "2B", "87", "50", "82", "54", _ "64", "26", "7D", "03", "40", "34", "4B", "1C", "73", "D1", "C4", "FD", "3B", "CC", "FB", "7F", "AB", "E6", "3E", _ "5B", "A5", "AD", "04", "23", "9C", "14", "51", "22", "F0", "29", "79", "71", "7E", "FF", "8C", "0E", "E2", "0C", _ "EF", "BC", "72", "75", "6F", "37", "A1", "EC", "D3", "8E", "62", "8B", "86", "10", "E8", "08", "77", "11", "BE", _ "92", "4F", "24", "C5", "32", "36", "9D", "CF", "F3", "A6", "BB", "AC", "5E", "6C", "A9", "13", "57", "25", "B5", _ "E3", "BD", "A8", "3A", "01", "05", "59", "2A", "46") SetKey Pass End Function Function SetKey(Pass) Dim i For i = 0 To 131 Step 10 If i = 130 Then key(i + 0) = Mid(Pass, 1, 2) key(i + 1) = Mid(Pass, 3, 2) Else key(i + 0) = Mid(Pass, 1, 2) key(i + 1) = Mid(Pass, 3, 2) key(i + 2) = Mid(Pass, 5, 2) key(i + 3) = Mid(Pass, 7, 2) key(i + 4) = Mid(Pass, 9, 2) key(i + 5) = Mid(Pass, 11, 2) key(i + 6) = Mid(Pass, 13, 2) key(i + 7) = Mid(Pass, 15, 2) key(i + 8) = Mid(Pass, 17, 2) key(i + 9) = Mid(Pass, 19, 2) End If Next End Function Function Dec(tmpString) Dim i Dim iLength iLength = Len(tmpString) For i = iLength To 1 Step -1 If IsNumeric(Mid(tmpString, i, 1)) Then Dec = Dec + ((16 ^ (iLength - i)) * Mid(tmpString, i, 1)) ElseIf Mid(tmpString, i, 1) = "A" Or Mid(tmpString, i, 1) = "a" Then Dec = Dec + ((16 ^ (iLength - i)) * 10) ElseIf Mid(tmpString, i, 1) = "B" Or Mid(tmpString, i, 1) = "b" Then Dec = Dec + ((16 ^ (iLength - i)) * 11) ElseIf Mid(tmpString, i, 1) = "C" Or Mid(tmpString, i, 1) = "c" Then Dec = Dec + ((16 ^ (iLength - i)) * 12) ElseIf Mid(tmpString, i, 1) = "D" Or Mid(tmpString, i, 1) = "d" Then Dec = Dec + ((16 ^ (iLength - i)) * 13) ElseIf Mid(tmpString, i, 1) = "E" Or Mid(tmpString, i, 1) = "e" Then Dec = Dec + ((16 ^ (iLength - i)) * 14) ElseIf Mid(tmpString, i, 1) = "F" Or Mid(tmpString, i, 1) = "f" Then Dec = Dec + ((16 ^ (iLength - i)) * 15) End If Next End Function %>

Mail To: info@3pc.com