Base64 Md5

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Base64 Md5 as PDF for free.

More details

  • Words: 3,349
  • Pages: 12
// // c_nsdata_encoding.m // // created by jeff ye on fri jun 20 2003. // copyright (c) 2003-2004 jeff ye. all rights reserved. // [email protected] /* this program is free software; you can redistribute it and/or modify it under the terms of the gnu general public license as published by the free software foundation; either version 2 of the license, or any later version. this program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. see the gnu general public license for more details. you should have received a copy of the gnu general public license along with this program; if not, write to the free software foundation, inc., 59 temple place - suite 330, boston, ma 02111-1307, usa. */ #import "c_nsdata_encoding.h" @implementation nsdata (encoding) const char alphabet[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="; - (nsdata *)base64encodeddata { const unsigned char *data = [self bytes]; int len = [self length]; nsmutabledata *target = [nsmutabledata datawithlength: ((len-1)/3 + 1)*4]; unsigned char *output = [target mutablebytes]; int i,j; unsigned long val; int quad, trip; for (i=0, j=0; i
{ val |= data[i+2]; quad = 1; }

}

output[j+3] val >>= 6; output[j+2] val >>= 6; output[j+1] val >>= 6; output[j] =

= alphabet[(quad ? (val&0x3f) : 64)]; = alphabet[(trip ? (val&0x3f) : 64)]; = alphabet[val & 0x3f]; alphabet[val];

return target; } - (nsdata *)decodedbase64data { const unsigned char *data = [self bytes]; int len = [self length]; nsmutabledata *target = [nsmutabledata datawithlength: (len/4)*3]; unsigned char *out = [target mutablebytes]; int i,j,k; unsigned long val; for (i=0, j=0; i+3='a' && data[k]<='z' ) { val <<= 6; val += data[k] - 'a'; } else if ( data[k]>='a' && data[k]<='z' ) { val <<= 6; val += data[k] - 'a' + 26; } else if ( data[k]>='0' && data[k]<='9' ) { val <<= 6; val += data[k] - '0' +52; } else if ( data[k] == '+' ) { val <<= 6; val += 62; } else if ( data[k] == '/') { val <<= 6; val += 63; }

else { val <<= 6; }

} memcpy(out+j, ((unsigned char *)(&val))+1, 3);

}

} return target;

// define the basic step of base-64 #define f(x, y, z) (((x) & (y)) | ((~x) & (z))) #define g(x, y, z) (((x) & (z)) | ((y) & (~z))) #define h(x, y, z) ((x) ^ (y) ^ (z)) #define i(x, y, z) ((y) ^ ((x) | (~z))) #define rotate_left(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) #define ff(a, b, c, d, (a) = rotate_left((a), #define gg(a, b, c, d, (a) = rotate_left((a), #define hh(a, b, c, d, (a) = rotate_left((a), #define ii(a, b, c, d, (a) = rotate_left((a),

x, s, (s)); x, s, (s)); x, s, (s)); x, s, (s));

ac) (a) ac) (a) ac) (a) ac) (a)

{ (a) += f((b), += (b); } { (a) += g((b), += (b); } { (a) += h((b), += (b); } { (a) += i((b), += (b); }

(c), (d)) + (x) + (uint32)(ac); (c), (d)) + (x) + (uint32)(ac); (c), (d)) + (x) + (uint32)(ac); (c), (d)) + (x) + (uint32)(ac);

// this method is re-write from the original codes from rivest - (nsdata *)md5digest { uint32 state[4]; unsigned char tail[128]; unsigned int i, j, k; unsigned int index; unsigned int padlen; const unsigned char *input = [self bytes]; unsigned int inputlen = [self length]; nsmutabledata *target = [nsmutabledata datawithlength: 16]; unsigned char *buffer = [target mutablebytes]; // initial state[0] = state[1] = state[2] = state[3] =

the context 0x67452301; 0xefcdab89; 0x98badcfe; 0x10325476;

// transform for ( i = 0; i+63 < inputlen; i += 64 ) { uint32 a = state[0], b = state[1], c = state[2], d = state[3]; uint32 x[16]; // load the 16 word session of input to the working array, little-endian for (j=0, k=0; k<64; j++, k+=4) {

x[j] = ((uint32)*(input+i+k)) | (((uint32)*(input+i+k+1))<<8) | (((uint32)*(input+i+k+2))<<16) | (((uint32)*(input+i+k+3))<<24); } // round ff(a, b, ff(d, a, ff(c, d, ff(b, c, ff(a, b, ff(d, a, ff(c, d, ff(b, c, ff(a, b, ff(d, a, ff(c, d, ff(b, c, ff(a, b, ff(d, a, ff(c, d, ff(b, c, // round gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, // round hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, // round ii(a, b, ii(d, a,

1 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d, 2 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d, 3 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d, 4 c, b,

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 7, 0xd76aa478); x[1], 12, 0xe8c7b756); x[2], 17, 0x242070db); x[3], 22, 0xc1bdceee); x[4], 7, 0xf57c0faf); x[5], 12, 0x4787c62a); x[6], 17, 0xa8304613); x[7], 22, 0xfd469501); x[8], 7, 0x698098d8); x[9], 12, 0x8b44f7af); x[10], 17, 0xffff5bb1); x[11], 22, 0x895cd7be); x[12], 7, 0x6b901122); x[13], 12, 0xfd987193); x[14], 17, 0xa679438e); x[15], 22, 0x49b40821);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[1], 5, 0xf61e2562); x[6], 9, 0xc040b340); x[11], 14, 0x265e5a51); x[0], 20, 0xe9b6c7aa); x[5], 5, 0xd62f105d); x[10], 9, 0x2441453); x[15], 14, 0xd8a1e681); x[4], 20, 0xe7d3fbc8); x[9], 5, 0x21e1cde6); x[14], 9, 0xc33707d6); x[3], 14, 0xf4d50d87); x[8], 20, 0x455a14ed); x[13], 5, 0xa9e3e905); x[2], 9, 0xfcefa3f8); x[7], 14, 0x676f02d9); x[12], 20, 0x8d2a4c8a);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[5], 4, 0xfffa3942); x[8], 11, 0x8771f681); x[11], 16, 0x6d9d6122); x[14], 23, 0xfde5380c); x[1], 4, 0xa4beea44); x[4], 11, 0x4bdecfa9); x[7], 16, 0xf6bb4b60); x[10], 23, 0xbebfbc70); x[13], 4, 0x289b7ec6); x[0], 11, 0xeaa127fa); x[3], 16, 0xd4ef3085); x[6], 23, 0x4881d05); x[9], 4, 0xd9d4d039); x[12], 11, 0xe6db99e5); x[15], 16, 0x1fa27cf8); x[2], 23, 0xc4ac5665);

d, x[0], 6, 0xf4292244); c, x[7], 10, 0x432aff97);

ii(c, ii(b, ii(a, ii(d, ii(c, ii(b, ii(a, ii(d, ii(c, ii(b, ii(a, ii(d, ii(c, ii(b,

d, c, b, a, d, c, b, a, d, c, b, a, d, c,

a, d, c, b, a, d, c, b, a, d, c, b, a, d,

b, a, d, c, b, a, d, c, b, a, d, c, b, a,

state[0] state[1] state[2] state[3]

+= += += +=

a; b; c; d;

x[14], 15, 0xab9423a7); x[5], 21, 0xfc93a039); x[12], 6, 0x655b59c3); x[3], 10, 0x8f0ccc92); x[10], 15, 0xffeff47d); x[1], 21, 0x85845dd1); x[8], 6, 0x6fa87e4f); x[15], 10, 0xfe2ce6e0); x[6], 15, 0xa3014314); x[13], 21, 0x4e0811a1); x[4], 6, 0xf7537e82); x[11], 10, 0xbd3af235); x[2], 15, 0x2ad7d2bb); x[9], 21, 0xeb86d391);

} // deal with the tail // padding index = inputlen&0x3f; memcpy(tail, input+i, index); padlen = (index < 56) ? (56 - index) : (120 - index); tail[index] = 0x80; if (padlen > 1) { memset(tail+index+1, 0, padlen -1); } *((uint32 *)(tail+index+padlen)) = nsswaphostinttolittle(inputlen<<3); *((uint32 *)(tail+index+padlen+4)) = nsswaphostinttolittle(inputlen>>29); // calculate the tail for ( i = 0; i+63 < index+padlen+8; i += 64 ) { uint32 a = state[0], b = state[1], c = state[2], d = state[3]; uint32 x[16]; // load the 16 word session of input to the working array, little-endian for (j=0, k=0; k<64; j++, k+=4) { x[j] = ((uint32)*(tail+i+k)) | (((uint32)*(tail+i+k+1))<<8) | (((uint32)*(tail+i+k+2))<<16) | (((uint32)*(tail+i+k+3))<<24); } // round ff(a, b, ff(d, a, ff(c, d, ff(b, c, ff(a, b, ff(d, a, ff(c, d, ff(b, c, ff(a, b, ff(d, a, ff(c, d,

1 c, b, a, d, c, b, a, d, c, b, a,

d, c, b, a, d, c, b, a, d, c, b,

x[0], 7, 0xd76aa478); x[1], 12, 0xe8c7b756); x[2], 17, 0x242070db); x[3], 22, 0xc1bdceee); x[4], 7, 0xf57c0faf); x[5], 12, 0x4787c62a); x[6], 17, 0xa8304613); x[7], 22, 0xfd469501); x[8], 7, 0x698098d8); x[9], 12, 0x8b44f7af); x[10], 17, 0xffff5bb1);

ff(b, c, ff(a, b, ff(d, a, ff(c, d, ff(b, c, // round gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, gg(a, b, gg(d, a, gg(c, d, gg(b, c, // round hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, hh(a, b, hh(d, a, hh(c, d, hh(b, c, // round ii(a, b, ii(d, a, ii(c, d, ii(b, c, ii(a, b, ii(d, a, ii(c, d, ii(b, c, ii(a, b, ii(d, a, ii(c, d, ii(b, c, ii(a, b, ii(d, a, ii(c, d, ii(b, c,

d, c, b, a, d, 2 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d, 3 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d, 4 c, b, a, d, c, b, a, d, c, b, a, d, c, b, a, d,

a, d, c, b, a,

x[11], x[12], x[13], x[14], x[15],

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[1], 5, 0xf61e2562); x[6], 9, 0xc040b340); x[11], 14, 0x265e5a51); x[0], 20, 0xe9b6c7aa); x[5], 5, 0xd62f105d); x[10], 9, 0x2441453); x[15], 14, 0xd8a1e681); x[4], 20, 0xe7d3fbc8); x[9], 5, 0x21e1cde6); x[14], 9, 0xc33707d6); x[3], 14, 0xf4d50d87); x[8], 20, 0x455a14ed); x[13], 5, 0xa9e3e905); x[2], 9, 0xfcefa3f8); x[7], 14, 0x676f02d9); x[12], 20, 0x8d2a4c8a);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[5], 4, 0xfffa3942); x[8], 11, 0x8771f681); x[11], 16, 0x6d9d6122); x[14], 23, 0xfde5380c); x[1], 4, 0xa4beea44); x[4], 11, 0x4bdecfa9); x[7], 16, 0xf6bb4b60); x[10], 23, 0xbebfbc70); x[13], 4, 0x289b7ec6); x[0], 11, 0xeaa127fa); x[3], 16, 0xd4ef3085); x[6], 23, 0x4881d05); x[9], 4, 0xd9d4d039); x[12], 11, 0xe6db99e5); x[15], 16, 0x1fa27cf8); x[2], 23, 0xc4ac5665);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 6, 0xf4292244); x[7], 10, 0x432aff97); x[14], 15, 0xab9423a7); x[5], 21, 0xfc93a039); x[12], 6, 0x655b59c3); x[3], 10, 0x8f0ccc92); x[10], 15, 0xffeff47d); x[1], 21, 0x85845dd1); x[8], 6, 0x6fa87e4f); x[15], 10, 0xfe2ce6e0); x[6], 15, 0xa3014314); x[13], 21, 0x4e0811a1); x[4], 6, 0xf7537e82); x[11], 10, 0xbd3af235); x[2], 15, 0x2ad7d2bb); x[9], 21, 0xeb86d391);

state[0] += a;

22, 0x895cd7be); 7, 0x6b901122); 12, 0xfd987193); 17, 0xa679438e); 22, 0x49b40821);

state[1] += b; state[2] += c; state[3] += d; } *((uint32 *((uint32 *((uint32 *((uint32

*)buffer) = nsswaphostinttolittle(state[0]); *)(buffer+4)) = nsswaphostinttolittle(state[1]); *)(buffer+8)) = nsswaphostinttolittle(state[2]); *)(buffer+12)) = nsswaphostinttolittle(state[3]);

return target; } // define the #define f4(x, #define g4(x, #define h4(x,

basic y, z) y, z) y, z)

step of base-64 (((x) & (y)) | ((~x) & (z))) (((x) & (y)) | ((y) & (z)) | ((x) & (z))) ((x) ^ (y) ^ (z))

#define ff4(a, b, c, d, x, s) { (a) += f4((b), (c), (d)) + (x); (a) = rotate_left((a), (s)); } #define gg4(a, b, c, d, x, s) { (a) += g4((b), (c), (d)) + (x) + (uint32)0x5a827999; (a) = rotate_left((a), (s)); } #define hh4(a, b, c, d, x, s) { (a) += h4((b), (c), (d)) + (x) + (uint32)0x6ed9eba1; (a) = rotate_left((a), (s)); } // this method is re-write from the original codes from rivest - (nsdata *)md4digest { uint32 state[4]; unsigned char tail[128]; unsigned int i, j, k; unsigned int index; unsigned int padlen; const unsigned char *input = [self bytes]; unsigned int inputlen = [self length]; nsmutabledata *target = [nsmutabledata datawithlength: 16]; unsigned char *buffer = [target mutablebytes]; // initial state[0] = state[1] = state[2] = state[3] =

the context 0x67452301; 0xefcdab89; 0x98badcfe; 0x10325476;

// transform for ( i = 0; i+63 < inputlen; i += 64 ) { uint32 a = state[0], b = state[1], c = state[2], d = state[3]; uint32 x[16]; // load the 16 word session of input to the working array, little-endian for (j=0, k=0; k<64; j++, k+=4) { x[j] = ((uint32)*(input+i+k)) | (((uint32)*(input+i+k+1))<<8) | (((uint32)*(input+i+k+2))<<16) | (((uint32)*(input+i+k+3))<<24);

} // round 1 ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, // round 2 gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, // round 3 hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, state[0] state[1] state[2] state[3]

+= += += +=

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 3); x[1], 7); x[2], 11); x[3], 19); x[4], 3); x[5], 7); x[6], 11); x[7], 19); x[8], 3); x[9], 7); x[10], 11); x[11], 19); x[12], 3); x[13], 7); x[14], 11); x[15], 19);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 3); x[4], 5); x[8], 9); x[12], 13); x[1], 3); x[5], 5); x[9], 9); x[13], 13); x[2], 3); x[6], 5); x[10], 9); x[14], 13); x[3], 3); x[7], 5); x[11], 9); x[15], 13);

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 3); x[8], 9); x[4], 11); x[12], 15); x[2], 3); x[10], 9); x[6], 11); x[14], 15); x[1], 3); x[9], 9); x[5], 11); x[13], 15); x[3], 3); x[11], 9); x[7], 11); x[15], 15);

a; b; c; d;

} // deal with the tail // padding index = inputlen&0x3f; memcpy(tail, input+i, index); padlen = (index < 56) ? (56 - index) : (120 - index); tail[index] = 0x80; if (padlen > 1) { memset(tail+index+1, 0, padlen -1); } *((uint32 *)(tail+index+padlen)) = nsswaphostinttolittle(inputlen<<3); *((uint32 *)(tail+index+padlen+4)) = nsswaphostinttolittle(inputlen>>29); // calculate the tail for ( i = 0; i+63 < index+padlen+8; i += 64 ) { uint32 a = state[0], b = state[1], c = state[2], d = state[3]; uint32 x[16]; // load the 16 word session of input to the working array, little-endian for (j=0, k=0; k<64; j++, k+=4) { x[j] = ((uint32)*(tail+i+k)) | (((uint32)*(tail+i+k+1))<<8) | (((uint32)*(tail+i+k+2))<<16) | (((uint32)*(tail+i+k+3))<<24); } // round 1 ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, ff4(a, b, c, ff4(d, a, b, ff4(c, d, a, ff4(b, c, d, // round 2 gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c, gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, gg4(a, b, c,

d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 3); x[1], 7); x[2], 11); x[3], 19); x[4], 3); x[5], 7); x[6], 11); x[7], 19); x[8], 3); x[9], 7); x[10], 11); x[11], 19); x[12], 3); x[13], 7); x[14], 11); x[15], 19);

d, c, b, a, d, c, b, a, d, c, b, a, d,

x[0], 3); x[4], 5); x[8], 9); x[12], 13); x[1], 3); x[5], 5); x[9], 9); x[13], 13); x[2], 3); x[6], 5); x[10], 9); x[14], 13); x[3], 3);

gg4(d, a, b, gg4(c, d, a, gg4(b, c, d, // round 3 hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, hh4(a, b, c, hh4(d, a, b, hh4(c, d, a, hh4(b, c, d, state[0] state[1] state[2] state[3]

+= += += +=

c, x[7], 5); b, x[11], 9); a, x[15], 13); d, c, b, a, d, c, b, a, d, c, b, a, d, c, b, a,

x[0], 3); x[8], 9); x[4], 11); x[12], 15); x[2], 3); x[10], 9); x[6], 11); x[14], 15); x[1], 3); x[9], 9); x[5], 11); x[13], 15); x[3], 3); x[11], 9); x[7], 11); x[15], 15);

a; b; c; d;

} *((uint32 *((uint32 *((uint32 *((uint32

*)buffer) = nsswaphostinttolittle(state[0]); *)(buffer+4)) = nsswaphostinttolittle(state[1]); *)(buffer+8)) = nsswaphostinttolittle(state[2]); *)(buffer+12)) = nsswaphostinttolittle(state[3]);

return target; } // tiny encrytion algorithm(tea) #define tea_delta 0x9e3779b9 #define tea_sum 0xe3779b90 // use 128 bits key to encrypt 64 bit plain data // plain is 8 bytes plain data // key is 16 bytes key data // crypt is output buffer, should be at least 8 bytes in length // rounds is encryption rounds - (void)tinyencrypt: (const unsigned long *)plain withkey: (const unsigned long *)key to: (unsigned long *)crypt forrounds: (unsigned int)power { unsigned long y,z,a,b,c,d; unsigned long sum = 0; unsigned int i; unsigned int rounds = 1<<power; y z a b c

= = = = =

plain[0]; plain[1]; key[0]; key[1]; key[2];

d = key[3]; for (i = 0; i < rounds; i++) { sum += tea_delta; y += (z << 4) + a ^ z + sum ^ (z >> 5) + b; z += (y << 4) + c ^ y + sum ^ (y >> 5) + d; }

}

crypt[0] = y; crypt[1] = z;

// use 128 bits key to decrypt 64 bit encrypted data // crypt is 8 bytes encrypted data // key is 16 bytes key data // plain is output buffer, should be at least 8 bytes in length // rounds is encryption rounds - (void)tinydecrypt: (const unsigned long *)crypt withkey: (const unsigned long *)key to: (unsigned long *)plain forrounds: (unsigned int)power { unsigned long y,z,a,b,c,d; unsigned int rounds = 1<<power; unsigned long sum = tea_delta<<power; unsigned int i; y z a b c d

= = = = = =

crypt[0]; crypt[1]; key[0]; key[1]; key[2]; key[3];

for (i = 0; i < rounds; i++) { z -= (y << 4) + c ^ y + sum ^ (y >> 5) + d; y -= (z << 4) + a ^ z + sum ^ (z >> 5) + b; sum -= tea_delta; }

}

plain[0] = y; plain[1] = z;

// return tea encrypted data - (nsdata *)jfteaencodewithkey: (nsdata *)thekey forrounds: (unsigned int)power { unsigned long *key; unsigned long *bytes; nsmutabledata *data = [nsmutabledata datawithdata: self]; unsigned char pad[8] = {0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00}; int padlength; int i; // adjust the key to 128 bits key = (unsigned long *)[[thekey md5digest] bytes]; // padding data padlength = 8-[data length]%8; if ( padlength != 8 ) {

[data appendbytes: pad length: padlength]; } else if ( [data length] == 0 ) { [data appendbytes: pad length: 8]; } bytes = (unsigned long *)[data mutablebytes]; for (i = 0; i < [data length]/4; i+=2) { [self tinyencrypt: bytes+i withkey: key to: bytes+i forrounds: power]; } return data; } - (nsdata *)jfteaencodewithkey: (nsdata *)thekey { return [self jfteaencodewithkey: thekey forrounds: 5]; } // return tea decrypted data - (nsdata *)jfteadecodewithkey: (nsdata *)thekey forrounds: (unsigned int)power { unsigned long *key; unsigned long *bytes; nsmutabledata *data = [nsmutabledata datawithdata: self]; unsigned char pad[8] = {0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00}; int padlength; int i; // adjust the key to 128 bits key = (unsigned long *)[[thekey md5digest] bytes]; // padding data padlength = 8-[data length]%8; if ( padlength != 8 ) { [data appendbytes: pad length: padlength]; } else if ( [data length] == 0 ) { [data appendbytes: pad length: 8]; } bytes = (unsigned long *)[data mutablebytes]; for (i = 0; i < [data length]/4; i+=2) { [self tinydecrypt: bytes+i withkey: key to: bytes+i forrounds: power]; } return data; } - (nsdata *)jfteadecodewithkey: (nsdata *)thekey { return [self jfteadecodewithkey: thekey forrounds: 5]; } @end

Related Documents

Base64 Md5
October 2019 13
Md5
July 2020 4
Md5.txt
June 2020 11
Algoritmo Md5
November 2019 15
Base64 Encoding Torn Apart
November 2019 16