Changeset d3307e2 for crypting.c
- Timestamp:
- 2005-12-13T23:07:05Z (19 years ago)
- Branches:
- master
- Children:
- 6aaa221
- Parents:
- 34759e6 (diff), b73ac9c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
crypting.c
r34759e6 rd3307e2 29 29 the programs will be built. */ 30 30 31 #ifndef CRYPTING_MAIN32 #define BITLBEE_CORE33 #include "bitlbee.h"34 #include "irc.h"35 31 #include "md5.h" 36 32 #include "crypting.h" … … 38 34 #include <stdio.h> 39 35 #include <stdlib.h> 40 41 #else42 43 typedef struct irc44 {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 #endif55 36 56 37 /*\ … … 83 64 84 65 85 char *hashpass (irc_t *irc) { 66 char *hashpass (const char *password) 67 { 86 68 md5_state_t md5state; 87 69 md5_byte_t digest[16]; … … 90 72 char *rv; 91 73 92 if ( irc->password == NULL) return (NULL);74 if (password == NULL) return (NULL); 93 75 94 rv = (char *)g_malloc (33); 95 memset (rv, 0, 33); 76 rv = g_new0 (char, 33); 96 77 97 78 md5_init (&md5state); 98 md5_append (&md5state, ( unsigned char *)irc->password, strlen (irc->password));79 md5_append (&md5state, (const unsigned char *)password, strlen (password)); 99 80 md5_finish (&md5state, digest); 100 81 … … 108 89 } 109 90 110 char *obfucrypt ( irc_t *irc, char *line)91 char *obfucrypt (char *line, const char *password) 111 92 { 112 93 int i, j; 113 94 char *rv; 114 95 115 if ( irc->password == NULL) return (NULL);96 if (password == NULL) return (NULL); 116 97 117 rv = g_new0 (char, strlen (line) + 1);98 rv = g_new0 (char, strlen (line) + 1); 118 99 119 100 i = j = 0; … … 121 102 /* Encrypt/obfuscate the line, using the password */ 122 103 if (*(signed char*)line < 0) *line = - (*line); 123 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];124 104 125 rv[j] = *line + irc->password[i]; /* Overflow intended */105 rv[j] = *line + password[i]; /* Overflow intended */ 126 106 127 107 line++; 128 if (! irc->password[++i]) i = 0;108 if (!password[++i]) i = 0; 129 109 j++; 130 110 } … … 133 113 } 134 114 135 char *deobfucrypt ( irc_t *irc, char *line)115 char *deobfucrypt (char *line, const char *password) 136 116 { 137 117 int i, j; 138 118 char *rv; 139 119 140 if ( irc->password == NULL) return (NULL);120 if (password == NULL) return (NULL); 141 121 142 rv = g_new0 (char, strlen (line) + 1);122 rv = g_new0 (char, strlen (line) + 1); 143 123 144 124 i = j = 0; 145 125 while (*line) { 146 126 /* Decrypt/deobfuscate the line, using the pass */ 147 rv[j] = *line - irc->password[i]; /* Overflow intended */127 rv[j] = *line - password[i]; /* Overflow intended */ 148 128 149 129 line++; 150 if (! irc->password[++i]) i = 0;130 if (!password[++i]) i = 0; 151 131 j++; 152 132 } … … 162 142 int main( int argc, char *argv[] ) 163 143 { 164 irc_t *irc = g_new0( irc_t, 1 );165 144 char *hash, *action, line[256]; 166 char* (*func)( irc_t *,char * );145 char* (*func)( char *, const char * ); 167 146 168 147 if( argc < 2 ) … … 174 153 } 175 154 176 irc->password = g_strdup( argv[1] ); 177 178 hash = hashpass( irc ); 155 hash = hashpass( argv[1] ); 179 156 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 180 157 … … 208 185 fgetc( stdin ); 209 186 210 out = func( irc, line);187 out = func( line, argv[1] ); 211 188 printf( "%s\n", out ); 212 189 g_free( out );
Note: See TracChangeset
for help on using the changeset viewer.