Advertisement
Guest User

MainAlgorithm

a guest
Jan 16th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.20 KB | None | 0 0
  1. #import <UIKit/UIKit.h>
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface MainView : UIView {
  5.     IBOutlet UITextField *passwordLength;
  6.     IBOutlet UISwitch *includeLowerCase;
  7.     IBOutlet UISwitch *includeNumbers;
  8.     IBOutlet UISwitch *includePunctuation;
  9.     IBOutlet UISwitch *includeUpperCase;
  10.     IBOutlet UISwitch *showPhonetics;
  11.     IBOutlet UITextField *password;
  12.     IBOutlet UITextView *phoneticPassword;
  13. }
  14.  
  15. @property (nonatomic, retain) UITextView *phoneticPassword;
  16. @property (nonatomic, retain) UITextField *passwordLength;
  17.  
  18. - (IBAction)setPasssword;
  19.  
  20. @end
  21.  
  22.  
  23.  
  24. #import "MainView.h"
  25.  
  26. #define RANDOM_SEED() srandom(time(NULL))
  27. #define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__)))
  28.  
  29. @implementation MainView
  30.  
  31. @synthesize phoneticPassword; //Şifrelerin baş harflarinden oluşan hatırlatıcı ipuçları
  32. @synthesize passwordLength; //Şifre uzunluğumuz.
  33.  
  34. - (id)initWithFrame:(CGRect)frame {
  35.     if (self = [super initWithFrame:frame]) {
  36.        
  37.     }
  38.     return self;
  39. }
  40.  
  41. - (IBAction)setPasssword {
  42.    
  43.     [UIView beginAnimations:nil context:NULL];
  44.     [UIView setAnimationDuration:1];
  45.     [password setAlpha:0.0];
  46.     [phoneticPassword setAlpha:0.0];
  47.     [UIView commitAnimations];
  48.    
  49.     [UIView beginAnimations:nil context:NULL];
  50.     [UIView setAnimationDuration:1];
  51.     [password setAlpha:0.85];
  52.     if(showPhonetics.on) {[phoneticPassword setAlpha:0.85];}
  53.     [UIView commitAnimations];
  54.    
  55.    
  56.     NSArray *keys = [NSArray arrayWithObjects:
  57.                     @"a", @"b", @"c", @"d", @"e",
  58.                     @"f", @"g", @"h", @"i", @"j",
  59.                     @"k", @"l", @"m", @"n", @"o",
  60.                     @"p", @"q", @"r", @"s", @"t",
  61.                     @"u", @"v", @"w", @"x", @"y", @"z",
  62.  
  63.                     @"A", @"B", @"C", @"D", @"E",
  64.                     @"F", @"G", @"H", @"I", @"J",
  65.                     @"K", @"L", @"M", @"N", @"O",
  66.                     @"P", @"Q", @"R", @"S", @"T",
  67.                     @"U", @"V", @"W", @"X", @"Y", @"Z",
  68.  
  69.                     @"0", @"1", @"2", @"3", @"4",
  70.                     @"5", @"6", @"7", @"8", @"9",
  71.  
  72.                     @"~", @"!", @"?", @"#", @"%",
  73.                     @"^", @"&", @"*", @"(", @")",
  74.  
  75.                      nil];
  76.    
  77.     NSArray *objects = [NSArray arrayWithObjects:
  78.                     @"ahmet", @"bilkent", @"can", @"delta", @"ekinoks",
  79.                     @"fırat", @"gaziantep", @"hakkı", @"ibrahim", @"jeep",
  80.                     @"kerem", @"lale", @"mesut", @"nergiz", @"ortaç",
  81.                     @"pehlivanoglu", @"queen", @"ramazan", @"serdar", @"taso",
  82.                     @"universite", @"vector", @"watson", @"xenon", @"yeşilmen", @"zirve",
  83.                        
  84.                     @"AHMET", @"BİLKENT", @"CAN", @"DELTA", @"EKİNOKS",
  85.                     @"FIRAT", @"GAZİANTEP", @"HAKKI", @"ISPARTA", @"JEEP",
  86.                     @"KAHRAMANMARAŞ", @"LALE", @"MESUT", @"NERGİZ", @"ORTAÇ",
  87.                     @"PEHLİVANOGLU", @"QUEEN", @"RAMAZAN", @"SERDAR", @"TASO",
  88.                     @"UNİVERSİTE", @"VECTOR", @"WATSON", @"XENON", @"YEŞİLMEN", @"ZİRVE",
  89.                        
  90.                     @"Sıfır", @"Bir", @"İki", @"Üç", @"Dört",
  91.                     @"Beş", @"Altı", @"Yedi", @"Sekiz", @"Dokuz",
  92.                        
  93.                     @"tilde", @"Ünlem", @"Soru İşareti", @"Sayı İşareti", @"Yüzde İşareti",
  94.                     @"Üs İşareti", @"Ampersand", @"Yıldız", @"Sol Parantez", @"Sag Parantez",
  95.                        
  96.                     nil];
  97.  
  98.     NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
  99.    
  100.     NSInteger iPassswordLength = [passwordLength.text intValue];
  101.     BOOL bShowPhonetics = showPhonetics.on;
  102.     BOOL bIncludeLowerCase = includeLowerCase.on;
  103.     BOOL bIncludeUpperCase = includeUpperCase.on;
  104.     BOOL bIncludeNumbers = includeNumbers.on;
  105.     BOOL bIncludePunctuation = includePunctuation.on;
  106.    
  107.     NSString* passwordText = @"";
  108.     NSString* phoneticText = @"";
  109.  
  110.     NSString* lowercaseChars = @"abcdefghijklmnopqrstuvwxyz";
  111.     NSString* uppercaseChars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  112.     NSString* numbersChars = @"0123456789";
  113.     NSString* punctuationChars = @"~!?#%^&*()";
  114.    
  115.     RANDOM_SEED();
  116.  
  117.     if(!bIncludeLowerCase && !bIncludeUpperCase && !bIncludeNumbers && !bIncludePunctuation)
  118.     {
  119.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PasswordGen" message:@"No password character set selected."
  120.                                                        delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  121.         [alert show];  
  122.         [alert release];
  123.  
  124.         return;
  125.     }
  126.    
  127.     NSString* passwordChars = @"";
  128.    
  129.     if(bIncludeLowerCase)
  130.         passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, lowercaseChars];
  131.    
  132.     if(bIncludeUpperCase)
  133.         passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, uppercaseChars];
  134.    
  135.     if(bIncludeNumbers)
  136.         passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, numbersChars];
  137.    
  138.     if(bIncludePunctuation)
  139.         passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, punctuationChars];
  140.    
  141.    
  142.     NSLog(@"Ahmet Dogan & Mesut Seker");
  143.  
  144.     for(NSInteger i=0; i<iPassswordLength; i++) {
  145.        
  146.         int index = RANDOM_INT(0, [passwordChars length]-1);
  147.  
  148.         NSRange range = NSMakeRange(index, 1);
  149.         NSString *passwordChar = [passwordChars substringWithRange:range]; 
  150.        
  151.         passwordText = [NSString stringWithFormat:@"%@%@", passwordText, passwordChar];
  152.        
  153.         NSLog(passwordChar); // Oluşturduğumuz şifreleri terminalde teker teker yazdırma.
  154.        
  155.         if(i>0)
  156.             phoneticText = [NSString stringWithFormat:@"%@, %@", phoneticText, [dictionary valueForKey:passwordChar]];
  157.         else
  158.             phoneticText = [dictionary valueForKey:passwordChar];
  159.     }
  160.    
  161.     password.text = @"";
  162.     password.text = passwordText;
  163.    
  164.     phoneticPassword.text = @"";
  165.    
  166.     if(bShowPhonetics)
  167.         phoneticPassword.text = phoneticText;
  168. }
  169.  
  170. -(IBAction) resignResponder {
  171.     [password resignFirstResponder];
  172.     [passwordLength resignFirstResponder];
  173. }
  174.  
  175. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  176.     if (textField == password) {
  177.         [password resignFirstResponder];
  178.     }
  179.     if (textField == passwordLength) {
  180.         [passwordLength resignFirstResponder];
  181.     }
  182.     return YES;
  183. }
  184.  
  185.  
  186. @end
  187.  
  188.  
  189.  
  190. #import <UIKit/UIKit.h>
  191.  
  192. @interface MainViewController : UIViewController {
  193.     IBOutlet UIButton *createPassword;
  194. }
  195. @property (nonatomic, retain) UIButton *createPassword;
  196.  
  197. @end
  198.  
  199.  
  200.  
  201.  
  202. #import "MainViewController.h"
  203. #import "MainView.h"
  204.  
  205. @implementation MainViewController
  206.  
  207. @synthesize createPassword;
  208.  
  209. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  210.     if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  211.        
  212.     }
  213.     return self;
  214. }
  215.  
  216. - (void)dealloc {
  217.     [createPassword release];
  218.     [super dealloc];
  219. }
  220.  
  221.  
  222. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement