Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • crypting.c

    ra301379c r34759e6  
    2929   the programs will be built. */
    3030
     31#ifndef CRYPTING_MAIN
     32#define BITLBEE_CORE
     33#include "bitlbee.h"
     34#include "irc.h"
    3135#include "md5.h"
    3236#include "crypting.h"
     
    3539#include <stdlib.h>
    3640
     41#else
     42
     43typedef struct irc
     44{
     45        char *password;
     46} irc_t;
     47
     48#include "md5.h"
     49#include "crypting.h"
     50#include <string.h>
     51#include <stdio.h>
     52#include <stdlib.h>
     53
     54#endif
     55
    3756/*\
    3857 * [SH] Do _not_ call this if it's not entirely sure that it will not cause
     
    6483
    6584
    66 char *hashpass (const char *password)
    67 {
     85char *hashpass (irc_t *irc) {
    6886        md5_state_t md5state;
    6987        md5_byte_t digest[16];
     
    7290        char *rv;
    7391       
    74         if (password == NULL) return (NULL);
    75        
    76         rv = g_new0 (char, 33);
     92        if (irc->password == NULL) return (NULL);
     93       
     94        rv = (char *)g_malloc (33);
     95        memset (rv, 0, 33);
    7796       
    7897        md5_init (&md5state);
    79         md5_append (&md5state, (const unsigned char *)password, strlen (password));
     98        md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password));
    8099        md5_finish (&md5state, digest);
    81100       
     
    89108}
    90109
    91 char *obfucrypt (char *line, const char *password)
     110char *obfucrypt (irc_t *irc, char *line)
    92111{
    93112        int i, j;
    94113        char *rv;
    95114       
    96         if (password == NULL) return (NULL);
    97        
    98         rv = g_new0 (char, strlen (line) + 1);
     115        if (irc->password == NULL) return (NULL);
     116       
     117        rv = g_new0(char, strlen (line) + 1);
    99118       
    100119        i = j = 0;
     
    102121                /* Encrypt/obfuscate the line, using the password */
    103122                if (*(signed char*)line < 0) *line = - (*line);
    104                
    105                 rv[j] = *line + password[i]; /* Overflow intended */
     123                if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];
     124               
     125                rv[j] = *line + irc->password[i]; /* Overflow intended */
    106126               
    107127                line++;
    108                 if (!password[++i]) i = 0;
     128                if (!irc->password[++i]) i = 0;
    109129                j++;
    110130        }
     
    113133}
    114134
    115 char *deobfucrypt (char *line, const char *password)
     135char *deobfucrypt (irc_t *irc, char *line)
    116136{
    117137        int i, j;
    118138        char *rv;
    119139       
    120         if (password == NULL) return (NULL);
    121        
    122         rv = g_new0 (char, strlen (line) + 1);
     140        if (irc->password == NULL) return (NULL);
     141       
     142        rv = g_new0(char, strlen (line) + 1);
    123143       
    124144        i = j = 0;
    125145        while (*line) {
    126146                /* Decrypt/deobfuscate the line, using the pass */
    127                 rv[j] = *line - password[i]; /* Overflow intended */
     147                rv[j] = *line - irc->password[i]; /* Overflow intended */
    128148               
    129149                line++;
    130                 if (!password[++i]) i = 0;
     150                if (!irc->password[++i]) i = 0;
    131151                j++;
    132152        }
     
    142162int main( int argc, char *argv[] )
    143163{
     164        irc_t *irc = g_new0( irc_t, 1 );
    144165        char *hash, *action, line[256];
    145         char* (*func)( char *, const char * );
     166        char* (*func)( irc_t *, char * );
    146167       
    147168        if( argc < 2 )
     
    153174        }
    154175       
    155         hash = hashpass( argv[1] );
     176        irc->password = g_strdup( argv[1] );
     177       
     178        hash = hashpass( irc );
    156179        action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    157180       
     
    185208                fgetc( stdin );
    186209               
    187                 out = func( line, argv[1] );
     210                out = func( irc, line );
    188211                printf( "%s\n", out );
    189212                g_free( out );
Note: See TracChangeset for help on using the changeset viewer.