Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified CaesarCipher/.DS_Store
Binary file not shown.
63 changes: 53 additions & 10 deletions CaesarCipher/CaesarCipher/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// main.m
// CaesarCipher
//
// Created by Michael Kavouras on 6/21/15.
// Created by Michael Kavouras, edited by Shena 🙋🏻 on 6/21/15.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE USE OF EMOJI! 👍

// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface CaesarCipher : NSObject

- (NSString *)decode:(NSString *)string offset:(int)offset;
- (NSString *)encode:(NSString *)string offset:(int)offset;
- (NSString *)decode:(NSString *)string offset:(int)offset;

// stated codebreaker method here:
- (BOOL) breakCode:(NSString *)stringOne
compareOneWithTwo:(NSString *)stringTwo;

@end

Expand All @@ -21,31 +26,69 @@ - (NSString *)encode:(NSString *)string offset:(int)offset {
if (offset > 25) {
NSAssert(offset < 26, @"offset is out of range. 1 - 25");
}
NSString *str = [string lowercaseString];
unsigned long count = [string length];
unichar result[count];
unichar buffer[count];
[string getCharacters:buffer range:NSMakeRange(0, count)];

[str getCharacters:buffer range:NSMakeRange(0, count)];

char allchars[] = "abcdefghijklmnopqrstuvwxyz";

for (int i = 0; i < count; i++) {
if (buffer[i] == ' ' || ispunct(buffer[i])) {
result[i] = buffer[i];
continue;
}

int low = islower(buffer[i]) ? 'a' : 'A';
result[i] = (buffer[i]%low + offset)%26 + low;

char *e = strchr(allchars, buffer[i]);
int idx= (int)(e - allchars);
int new_idx = (idx + offset) % strlen(allchars);

result[i] = allchars[new_idx];
}

return [NSString stringWithCharacters:result length:count];
}

- (NSString *)decode:(NSString *)string offset:(int)offset {
return [self encode:string offset: (26 - offset)];
}

// implementation of codebreaker method:
- (BOOL) breakCode:(NSString *)stringOne
compareOneWithTwo:(NSString *)stringTwo{

BOOL isEqualTo = NO;

for (int i = 1; i < 26; i++) {
NSString *decodeCyphStringOne = [self decode:stringOne offset:i];
for (int j = 1; j < 26; j++) {
NSString *decodeCyphStringTwo = [self decode:stringTwo offset:j];
if ([decodeCyphStringOne isEqualTo:decodeCyphStringTwo])
isEqualTo = YES;
}
}
return isEqualTo;
}
@end

int main(int argc, const char * argv[]) {
@autoreleasepool {


CaesarCipher *testStrings = [[CaesarCipher alloc]init];

// I set words for the program to encode/decode:
[testStrings encode:@"bananas" offset:3];
[testStrings decode:@"edqdqdv" offset:3];

// I printed values to show the encode/decode is working:
NSLog(@"%@ = the encoded word", [testStrings encode:@"bananas" offset:3]);
NSLog(@"%@ = the decoded word", [testStrings decode:@"edqdqdv" offset:3]);

// we can use the BOOL method to test the two words here:
BOOL isEqualTo = [testStrings breakCode:@"bananas" compareOneWithTwo:@"edqdqdv"];
NSLog(@"is codebreaker working? 1 = YES, 2 = NOPE: %d", isEqualTo);

}
}
return 0;
}
2 changes: 2 additions & 0 deletions Election/Election/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ - (BOOL)pollsOpen {
int main(int argc, const char * argv[]) {
@autoreleasepool {



}
return 0;
}
91 changes: 86 additions & 5 deletions Person/Person/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// main.m
// Person
//
// Created by Michael Kavouras on 6/21/15.
// Created by Michael Kavouras, edited by Shena 💁🏻 on 6/21/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

// We always start with the INTERFACE:
@interface Person: NSObject

// And then declare a few METHODS:
- (void)setName:(NSString *)name;
- (NSString *)name;

Expand All @@ -19,14 +20,28 @@ - (NSString *)city;
- (void)setPhoneNumber:(NSString *)phoneNumber;
- (NSString *)phoneNumber;

// I added another method that will show each person's shoe size!
- (void)setShoeSize:(NSString *)shoeSize;
- (NSString *)shoeSize;

// This method will eventually check the same city:
-(BOOL)checkSameCity:(Person *)aPerson;

// This method adds a child:
-(Person *)haveChild;

@end

// We name the properties:
// I learned that we only have to declare variables here, so "have child" and "checkSameCity" don't qualify:
@implementation Person {
NSString *_name;
NSString *_phoneNumber;
NSString *_city;
NSString *_shoeSize;
}

// Then we add the setter/getter methods:
- (void)setName:(NSString *)name {
_name = name;
}
Expand All @@ -51,13 +66,79 @@ - (NSString *)phoneNumber {
return _phoneNumber;
}

- (void)setShoeSize:(NSString *)shoeSize {
_shoeSize = shoeSize;
}

- (NSString *)shoeSize {
return _shoeSize;
}

// Here are the methods for checking the city:
-(BOOL) checkSameCity:(Person *)aPerson; {
// note: "==" does not work in obj c, use "isEqualToString" instead, like this:
if([[aPerson city] isEqualToString: [self city]]) {
return YES;
} else {
return NO;
}
}

// And this method will return a child:
-(Person *)haveChild {
Person *child = [[Person alloc]init];
[child setCity: [self city]];
[child setPhoneNumber: [self phoneNumber]];
return child;
}

@end


int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");


Person *fred = [[Person alloc]init];
Person *wilma = [[Person alloc]init];

// we can set our Person's properties:

[fred setName: @"Fred"];
[fred setCity: @"Bedrock"];
[fred setPhoneNumber: @"123-4567"];
[fred setShoeSize: @"9.5"];

[wilma setName: @"Wilma"];
[wilma setCity: @"Bedrock"];
[wilma setPhoneNumber: @"123-4567"];
[wilma setShoeSize: @"7"];

BOOL checkSameCity = [wilma checkSameCity: fred];
NSLog(@"Do Fred and Wilma live in the same city? 1 = yes, 0 = no. Answer: %i", checkSameCity);

// to display Fred and Wilma's names, we call the "getter"
NSString *fredsName = [fred name];
NSLog(@"Our first person is called %@", fredsName);
NSString *wilmasName = [wilma name];
NSLog(@"Our second person is called %@", wilmasName);

NSString *fredsPhone = [fred phoneNumber];
NSLog(@"%@'s phone number is %@", fredsName, fredsPhone);

NSString *wilmasShoeSize = [wilma shoeSize];
NSLog(@"%@ wears size %@ shoes", wilmasName, wilmasShoeSize);

NSString *wilmasCity = [wilma city];
NSLog(@"%@ lives in %@", wilmasName, wilmasCity);

[fred haveChild];
Person *fredsBaby = [fred haveChild];
[fredsBaby setCity: @"Dino Town"];
[fredsBaby setPhoneNumber: @"123-4567"];
NSLog(@"Fred's baby lives in %@", [fredsBaby city]);


}
return 0;
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ Write a program to simulate an election. Create a class called **VotingSimulator
4. Ask the ElectionManager to ***initiatePolling***
5. Follow the instructions on the console. After each round of polling you will be asked(within the console) whether you want to continue or not.
6. Ask the ElectionManager to ***displayResults***

this is my added text...

me right now: 💆🏻