SDLGameEngine

src/sgemisc.c

00001 /*
00002  * Copyright (c) 2007 Heiko Irrgang
00003  *
00004  * The license and distribution terms for this file may be
00005  * found in the file COPYING in this distribution or at
00006  * http://93-interactive.com/cms/products/software/sdl-game-engine/license/
00007  */
00008 
00009 #include <sge.h>
00010 
00011 int sgeGetDistance(int x, int y, int xx, int yy) {
00012         int distx=xx-x;
00013         int disty=yy-y;
00014 
00015         return (int) sgeRound(sqrt(distx*distx+disty*disty));
00016 }
00017 
00018 char *sgeMD5(const unsigned char *data, unsigned int datalen) {
00019         char *ret=NULL;
00020         int i;
00021         md5_state_t md5;
00022         md5_byte_t digest[16];
00023 
00024         md5_init(&md5);
00025         md5_append(&md5, (const md5_byte_t *)data, datalen);
00026         md5_finish(&md5, digest);
00027 
00028         sgeMalloc(ret, char, 33);
00029         for (i=0; i<16; i++) {
00030                 sprintf(ret+i*2, "%0x", digest[i]);
00031         }
00032         return ret;
00033 }
00034 
00035 char *sgeSHA1(const unsigned char *data, unsigned int datalen) {
00036         char *ret=NULL;
00037         int i=0;
00038         SHA1Context sha;
00039 
00040         SHA1Reset(&sha);
00041         SHA1Input(&sha, data, datalen);
00042         SHA1Result(&sha);
00043 
00044         sgeMalloc(ret, char, 41);
00045         for (i=0; i<5; i++) {
00046                 sprintf(ret+i*8, "%08x", sha.Message_Digest[i]);
00047         }
00048         return ret;
00049 }
00050 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines