/* Ultima Online login encryption algorithm 0.1 by Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org Created only for the first part of the login mechanism used in my uologin program. Based on Ultima Online version 5.01d patch 23 Copyright 2005,2006 Luigi Auriemma 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 (at your option) 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 http://www.gnu.org/licenses/gpl.txt */ unsigned short uolentable[] = { 0x0068, 0x0005, 0x0007, 0x8000, 0x0002, 0x0005, 0x0005, 0x0007, 0x000e, 0x0005, 0x000b, 0x0007, 0x8000, 0x0003, 0x8000, 0x003d, 0x00d7, 0x8000, 0x8000, 0x000a, 0x0006, 0x0009, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0025, 0x8000, 0x0005, 0x0004, 0x0008, 0x0013, 0x0008, 0x0003, 0x001a, 0x0007, 0x0014, 0x0005, 0x0002, 0x0005, 0x0001, 0x0005, 0x0002, 0x0002, 0x0011, 0x000f, 0x000a, 0x0005, 0x8000, 0x0002, 0x0002, 0x000a, 0x028d, 0x8000, 0x0008, 0x0007, 0x0009, 0x8000, 0x8000, 0x8000, 0x0002, 0x0025, 0x8000, 0x00c9, 0x8000, 0x8000, 0x0229, 0x02c9, 0x0005, 0x8000, 0x000b, 0x0049, 0x005d, 0x0005, 0x0009, 0x8000, 0x8000, 0x0006, 0x0002, 0x8000, 0x8000, 0x8000, 0x0002, 0x000c, 0x0001, 0x000b, 0x006e, 0x006a, 0x8000, 0x8000, 0x0004, 0x0002, 0x0049, 0x8000, 0x0031, 0x0005, 0x0009, 0x000f, 0x000d, 0x0001, 0x0004, 0x8000, 0x0015, 0x8000, 0x8000, 0x0003, 0x0009, 0x0013, 0x0003, 0x000e, 0x8000, 0x001c, 0x8000, 0x0005, 0x0002, 0x8000, 0x0023, 0x0010, 0x0011, 0x8000, 0x0009, 0x8000, 0x0002, 0x8000, 0x000d, 0x0002, 0x8000, 0x003e, 0x8000, 0x0002, 0x0027, 0x0045, 0x0002, 0x8000, 0x8000, 0x0042, 0x8000, 0x8000, 0x8000, 0x000b, 0x8000, 0x8000, 0x8000, 0x0013, 0x0041, 0x8000, 0x0063, 0x8000, 0x0009, 0x8000, 0x0002, 0x8000, 0x001a, 0x8000, 0x0102, 0x0135, 0x0033, 0x8000, 0x8000, 0x0003, 0x0009, 0x0009, 0x0009, 0x0095, 0x8000, 0x8000, 0x0004, 0x8000, 0x8000, 0x0005, 0x8000, 0x8000, 0x8000, 0x8000, 0x000d, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0040, 0x0009, 0x8000, 0x8000, 0x0003, 0x0006, 0x0009, 0x0003, 0x8000, 0x8000, 0x8000, 0x0024, 0x8000, 0x8000, 0x8000, 0x0006, 0x00cb, 0x0001, 0x0031, 0x0002, 0x0006, 0x0006, 0x0007, 0x8000, 0x0001, 0x8000, 0x004e, 0x8000, 0x0002, 0x0019, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x010c, 0x8000, 0x8000, 0x0009, 0x8000 }; struct { unsigned int e1; unsigned int e2; unsigned int e3; unsigned int e4; } uoenc; void uocalcenc(unsigned int ip) { unsigned int pi = ~ip; uoenc.e1 = ((pi ^ 0x00001357) << 16) | ((ip ^ 0xffffaaaa) & 0x0000ffff); uoenc.e2 = ((ip ^ 0x43210000) >> 16) | ((pi ^ 0xabcdffff) & 0xffff0000); uoenc.e3 = (((ip ^ pi) & 0x0f0f0f0f) ^ ip) ^ 0xa76e25ea; uoenc.e4 = (((ip ^ pi) & 0x0f0f0f0f) ^ pi) ^ 0xf4bc319d; } unsigned short uopcklen(unsigned char *data) { // unsigned short num; // if(*data < 222) { // num = uolentable[*data] >> 15; // if(num) return(*(unsigned short *)(data + 1)); // } // return(uolentable[*data]); if(*data < 222) { return(uolentable[*data]); } return(0); } /* it's the same for both encryption and decryption */ void uoencrypt(unsigned char *data, int len) { unsigned int t1, t2; for(; len--; data++) { *data ^= uoenc.e1; t1 = uoenc.e1; t2 = uoenc.e2; uoenc.e1 = ((t1 >> 1) | (t2 << 31)) ^ 0xa2417e7f; t2 = ((t2 >> 1) | (t1 << 31)) ^ 0x2eaba7ec; uoenc.e2 = ((t2 >> 1) | (t1 << 31)) ^ 0x2eaba7ed; } } int uobuildlogin(unsigned char *buff, unsigned char *user, unsigned char *pass) { int len; buff[0] = 0x80; strncpy(buff + 1, user, 30); strncpy(buff + 1 + 30, pass, 31); len = uopcklen(buff); uoencrypt(buff, len); return(len); }