| 148 | return ret |
| 149 | |
| 150 | def encrypt(string,power,n,bits=128): |
| 151 | string=string.replace('/',"/s").replace('\0',"/0") # escape \x00 |
| 152 | # because crypt() ignores leading zeros |
| 153 | bytes=bits//8 |
| 154 | lst=[] |
| 155 | while string: |
| 156 | lst.append(string[:bytes-1]) # string must have a lesser value than |
| 157 | string=string[bytes-1:] # n, so truncate and pad |
| 158 | for i in range(len(lst)): |
| 159 | lst[i]=crypt(lst[i],power,n) |
| 160 | lst[i]='\0'*(bytes-len(lst[i]))+lst[i] # pad with zeros |
| 161 | # don't worry about removing these later: crypt() ignores |
| 162 | # leading zeros already, so they are always removed |
| 163 | return ''.join(lst) # the length of this must be a multiple of bytes |
| 164 | |
| 165 | def decrypt(string,power,n,bits=128): |
| 166 | bytes=bits//8 |