-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.m
More file actions
36 lines (28 loc) · 904 Bytes
/
Utility.m
File metadata and controls
36 lines (28 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Utility.m
// DataManager
//
// Created by Adam Chin on 5/31/15.
// Copyright (c) 2015 Adam Chin. All rights reserved.
//
#import "Utility.h"
@implementation Utility
// can be used for a simple form of encryption
+(NSArray *)convertStringToByteArray:(NSString *)string
{
NSData *stringData = [string dataUsingEncoding:NSUTF8StringEncoding];
const unsigned char * bytes = [stringData bytes];
const NSUInteger length = [stringData length];
NSMutableArray * const byteData = [[NSMutableArray alloc]initWithCapacity:length];
char byteChars[3] = {'\0','\0','\0'};
unsigned long wholeByte;
for (int i = 0; i < length;)
{
byteChars[0] = bytes[i++];
byteChars[1] = bytes[i++];
wholeByte = strtoul(byteChars, NULL, 16);
[byteData addObject:[NSNumber numberWithUnsignedLong:wholeByte]];
}
return byteData;
}
@end