File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,14 +8,14 @@ cdef extern from "crypt_wrapper.h":
88 void _decrypt_into(const char * encrypted, char * unencrypted)
99
1010cdef char * _decrypt(const char * encrypted):
11- cdef char * unencrypted = < char * > malloc(( len (encrypted)) * sizeof(char ))
11+ cdef char * unencrypted = < char * > malloc(sizeof(encrypted ))
1212 if not unencrypted:
1313 return NULL # malloc failed
1414 _decrypt_into(encrypted, unencrypted)
1515 return unencrypted
1616
1717cdef char * _encrypt(const char * unencrypted):
18- cdef char * encrypted = < char * > malloc(( len (unencrypted)) * sizeof(char ))
18+ cdef char * encrypted = < char * > malloc(sizeof(unencrypted ))
1919 if not encrypted:
2020 return NULL # malloc failed
2121 _encrypt_into(unencrypted, encrypted)
Original file line number Diff line number Diff line change 88void _encrypt_into (const char * unencrypted , char * encrypted ) {
99 uint8_t unencrypted_byte ;
1010 uint8_t key = 171 ;
11- for (unsigned i = 0 ; i < strlen (unencrypted ); i ++ ) {
11+ unsigned long len = strlen (unencrypted );
12+ for (unsigned i = 0 ; i < len ; i ++ ) {
1213 unencrypted_byte = unencrypted [i ];
1314 key = key ^ unencrypted_byte ;
1415 encrypted [i ] = key ;
1516 }
17+ encrypted [len ] = '\0' ;
1618}
1719void _decrypt_into (const char * encrypted , char * unencrypted ) {
1820 uint8_t unencrypted_byte ;
1921 uint8_t encrypted_byte ;
2022 uint8_t key = 171 ;
23+ unsigned long len = strlen (encrypted );
2124 for (unsigned i = 0 ; i < strlen (encrypted ); i ++ ) {
2225 encrypted_byte = encrypted [i ];
2326 unencrypted_byte = key ^ encrypted_byte ;
2427 key = encrypted_byte ;
2528 unencrypted [i ] = unencrypted_byte ;
2629 }
30+ unencrypted [len ] = '\0' ;
2731}
You can’t perform that action at this time.
0 commit comments