Commit 68bcd10bcd7a9748d9004cf1dd8c3e90ff1d48b0
1 parent
f3d37f10
0.1.25
Showing
5 changed files
with
189 additions
and
4 deletions
CNLiveBusinessTools.podspec
CNLiveBusinessTools/Classes/CNLiveEscpTools.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveEscpTools.h | |
| 3 | +// CNLiveBusinessTools | |
| 4 | +// | |
| 5 | +// Created by open on 2021/12/22. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import <Foundation/Foundation.h> | |
| 9 | + | |
| 10 | +NS_ASSUME_NONNULL_BEGIN | |
| 11 | + | |
| 12 | +@interface CNLiveEscpTools : NSObject | |
| 13 | +/// esp加密 | |
| 14 | +/// @param src 需要加密字符串 | |
| 15 | ++(NSString *)esp:(NSString *)src; | |
| 16 | +/// esp解密 | |
| 17 | +/// @param src 需要解密字符串 | |
| 18 | ++(NSString *)unesp:(NSString *)src; | |
| 19 | +@end | |
| 20 | + | |
| 21 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveBusinessTools/Classes/CNLiveEscpTools.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveEscpTools.m | |
| 3 | +// CNLiveBusinessTools | |
| 4 | +// | |
| 5 | +// Created by open on 2021/12/22. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import "CNLiveEscpTools.h" | |
| 9 | + | |
| 10 | +@implementation CNLiveEscpTools | |
| 11 | + | |
| 12 | +/// esp加密 | |
| 13 | +/// @param src 需要加密字符串 | |
| 14 | ++(NSString *)esp:(NSString *)src | |
| 15 | +{ | |
| 16 | + return esp(src); | |
| 17 | +} | |
| 18 | + | |
| 19 | +/// esp解密 | |
| 20 | +/// @param src 需要解密字符串 | |
| 21 | ++(NSString *)unesp:(NSString *)src | |
| 22 | +{ | |
| 23 | + return unesp(src); | |
| 24 | +} | |
| 25 | + | |
| 26 | + | |
| 27 | +NSString * tohex(int tmpid) | |
| 28 | +{ | |
| 29 | + NSString *nLetterValue; | |
| 30 | + NSString *str =@""; | |
| 31 | + long long int ttmpig; | |
| 32 | + for (int i = 0; i<9; i++) { | |
| 33 | + ttmpig=tmpid%16; | |
| 34 | + tmpid=tmpid/16; | |
| 35 | + switch (ttmpig) | |
| 36 | + { | |
| 37 | + case 10: | |
| 38 | + nLetterValue =@"A";break; | |
| 39 | + case 11: | |
| 40 | + nLetterValue =@"B";break; | |
| 41 | + case 12: | |
| 42 | + nLetterValue =@"C";break; | |
| 43 | + case 13: | |
| 44 | + nLetterValue =@"D";break; | |
| 45 | + case 14: | |
| 46 | + nLetterValue =@"E";break; | |
| 47 | + case 15: | |
| 48 | + nLetterValue =@"F";break; | |
| 49 | + default:nLetterValue=[[NSString alloc]initWithFormat:@"%lli",ttmpig]; | |
| 50 | + | |
| 51 | + } | |
| 52 | + str = [nLetterValue stringByAppendingString:str]; | |
| 53 | + if (tmpid == 0) { | |
| 54 | + break; | |
| 55 | + } | |
| 56 | + | |
| 57 | + } | |
| 58 | + return str; | |
| 59 | +} | |
| 60 | + | |
| 61 | + | |
| 62 | +NSString * esp(NSString * src) { | |
| 63 | + int i; | |
| 64 | + NSString* tmp = @""; | |
| 65 | + for (i=0; i<[src length]; i++) { | |
| 66 | + unichar c = [src characterAtIndex:(NSUInteger)i]; | |
| 67 | + if(isdigit(c)||isupper(c)|islower(c)){ | |
| 68 | + tmp = [NSString stringWithFormat:@"%@%c",tmp,c]; | |
| 69 | + }else if ((int)c < 256 ) { | |
| 70 | + tmp = [NSString stringWithFormat:@"%@%@",tmp,@"%"]; | |
| 71 | + if((int)c <16){ | |
| 72 | + tmp =[NSString stringWithFormat:@"%@%@",tmp,@"0"]; | |
| 73 | + } | |
| 74 | + tmp = [NSString stringWithFormat:@"%@%@",tmp,tohex((int)c)]; | |
| 75 | + }else{ | |
| 76 | + tmp = [NSString stringWithFormat:@"%@%@",tmp,@"%u"]; | |
| 77 | + tmp = [NSString stringWithFormat:@"%@%@",tmp,tohex(c)]; | |
| 78 | + } | |
| 79 | + } | |
| 80 | + return tmp; | |
| 81 | +} | |
| 82 | + | |
| 83 | +Byte getInt(char c){ | |
| 84 | + if(c>='0'&&c<='9'){ | |
| 85 | + return c-'0'; | |
| 86 | + }else if((c>='a'&&c<='f')){ | |
| 87 | + return 10+(c-'a'); | |
| 88 | + }else if((c>='A'&&c<='F')){ | |
| 89 | + return 10+(c-'A'); | |
| 90 | + } | |
| 91 | + return c; | |
| 92 | +} | |
| 93 | +int getIntStr(NSString *src,int len){ | |
| 94 | + if(len==2){ | |
| 95 | + Byte c1 = getInt([src characterAtIndex:(NSUInteger)0]); | |
| 96 | + Byte c2 = getInt([src characterAtIndex:(NSUInteger)1]); | |
| 97 | + return ((c1&0x0f)<<4)|(c2&0x0f); | |
| 98 | + }else{ | |
| 99 | + | |
| 100 | + Byte c1 = getInt([src characterAtIndex:(NSUInteger)0]); | |
| 101 | + | |
| 102 | + Byte c2 = getInt([src characterAtIndex:(NSUInteger)1]); | |
| 103 | + Byte c3 = getInt([src characterAtIndex:(NSUInteger)2]); | |
| 104 | + Byte c4 = getInt([src characterAtIndex:(NSUInteger)3]); | |
| 105 | + return( ((c1&0x0f)<<12) | |
| 106 | + |((c2&0x0f)<<8) | |
| 107 | + |((c3&0x0f)<<4) | |
| 108 | + |(c4&0x0f)); | |
| 109 | + } | |
| 110 | +} | |
| 111 | + | |
| 112 | +NSString* unesp(NSString* src) { | |
| 113 | + int lastPos = 0; | |
| 114 | + int pos=0; | |
| 115 | + unichar ch; | |
| 116 | + NSString * tmp = @""; | |
| 117 | + while(lastPos<src.length){ | |
| 118 | + NSRange range; | |
| 119 | + | |
| 120 | + range = [src rangeOfString:@"%" options:NSLiteralSearch range:NSMakeRange(lastPos, src.length-lastPos)]; | |
| 121 | + if (range.location != NSNotFound) { | |
| 122 | + pos = (int)range.location; | |
| 123 | + }else{ | |
| 124 | + pos = -1; | |
| 125 | + } | |
| 126 | + | |
| 127 | + if(pos == lastPos){ | |
| 128 | + | |
| 129 | + if([src characterAtIndex:(NSUInteger)(pos+1)]=='u'){ | |
| 130 | + NSString* ts = [src substringWithRange:NSMakeRange(pos+2,4)]; | |
| 131 | + | |
| 132 | + int d = getIntStr(ts,4); | |
| 133 | + ch = (unichar)d; | |
| 134 | + NSLog(@"%@%C",tohex(d),ch); | |
| 135 | + tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%C",ch]]; | |
| 136 | + | |
| 137 | + lastPos = pos+6; | |
| 138 | + | |
| 139 | + }else{ | |
| 140 | + NSString* ts = [src substringWithRange:NSMakeRange(pos+1,2)]; | |
| 141 | + int d = getIntStr(ts,2); | |
| 142 | + ch = (unichar)d; | |
| 143 | + tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%C",ch]]; | |
| 144 | + lastPos = pos+3; | |
| 145 | + } | |
| 146 | + | |
| 147 | + }else{ | |
| 148 | + if(pos ==-1){ | |
| 149 | + NSString* ts = [src substringWithRange:NSMakeRange(lastPos,src.length-lastPos)]; | |
| 150 | + | |
| 151 | + tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%@",ts]]; | |
| 152 | + lastPos = (int)src.length; | |
| 153 | + }else{ | |
| 154 | + NSString* ts = [src substringWithRange:NSMakeRange(lastPos,pos-lastPos)]; | |
| 155 | + | |
| 156 | + tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%@",ts]]; | |
| 157 | + lastPos = pos; | |
| 158 | + } | |
| 159 | + } | |
| 160 | + } | |
| 161 | + return tmp; | |
| 162 | +} | |
| 163 | +@end | ... | ... |
Example/CNLiveBusinessTools/CNLiveAppDelegate.m
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | #import "CNLiveAppDelegate.h" |
| 10 | 10 | #import "CNLiveQQEmotionManager.h" |
| 11 | 11 | #import "CNLiveBusinessTools.h" |
| 12 | +#import "CNLiveEscpTools.h" | |
| 12 | 13 | @implementation CNLiveAppDelegate |
| 13 | 14 | |
| 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ... | ... |
Example/Podfile
| 1 | 1 | source 'http://bj.gitlab.cnlive.com/ios-team/CNLiveRepos.git' |
| 2 | -#source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git' | |
| 3 | -source 'https://github.com/CocoaPods/Specs.git' | |
| 2 | +source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git' | |
| 3 | +#source 'https://github.com/CocoaPods/Specs.git' | |
| 4 | 4 | |
| 5 | 5 | use_frameworks! |
| 6 | 6 | |
| 7 | -platform :ios, '9.0' | |
| 7 | +platform :ios, '10.0' | |
| 8 | 8 | |
| 9 | 9 | target 'CNLiveBusinessTools_Example' do |
| 10 | 10 | pod 'CNLiveBusinessTools', :path => '../' | ... | ... |