1.base64加密,string为待加密字串
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *result = [data base64EncodedStringWithOptions:0];
2.base64解密,string为待解密字串
NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:0];
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
3.凯撒密码加解密为同一个算法,加密与解密的位移数互为相反数,即加密位移为1,解密为-1
/** 凯撒密码加解密方式 string为待加密或待解密的字串 count偏移量 */
+(NSString*) caesarCipherEncode:(NSString*)string withShift:(int)count
{
NSMutableArray *arr = [NSMutableArray array];
for(int i = 0;i < string.length;i++)
{
unichar asciiCode = [string characterAtIndex:i];
asciiCode = asciiCode + count; //右偏移count个单位
NSString *encryptStr = [NSString stringWithFormat:@"%C", asciiCode]; //注意:此处必须使用%C 不能用%c,否则会有乱码!
[arr addObject:encryptStr];
}
return [arr componentsJoinedByString:@""];
}