#include <Keypad.h>
#include <Servo.h>
Servo myservo;
char d,d1,d2,d3,d4,d5,d6,d7,d10,d11,d12,d13,d14,d15,d16,d17;
char final[8];
char given[8];
int count;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
myservo.attach(2);
assign();
//cipher(final);
Serial.begin(9600);
Serial.println( "ENTER PASSWORD");
count = 0;
myservo.write(0);
}
void loop() {
char key = keypad.getKey();
if(key){
given[count] = key;
Serial.print(key);
count++;
}
if (count == 8) {
given[count] = '\n';
int arg = unlock(given);
if (arg == 1){
myservo.write(90);
Serial.println(" correct password");
delay(5000);
myservo.write(0);
count = 0;
}
else {
Serial.println(" Incorrect password");
count = 0;
}
}
}
void assign(){
char pas[] = {'4', '4', '4', '4', '4', '4', '4', '4'};
memcpy(final, pas, sizeof(final));
}
int unlock(char a[]){
int iscorr = 0;
cipher(a);
for(int blud = 0;a[blud]!='\n';blud++){
if( a[blud] == final[blud])
iscorr++;
}
if( iscorr == 8)
return 1;
return 0;
}
void cipher(char buhe[]) {
for (int yz = 0; yz < 8; yz++) {
buhe[yz] += 3;
if (buhe[yz] > '9') {
buhe[yz] -= 10;
} else if (buhe[yz] < '0') {
buhe[yz] += 10;
}
}
}
/*
void cipfinal(char buhe[]){
for (int yz = 0;yz<8;yz++){
buhe[yz] += '5';
if (buhe[yz]>9)
buhe[yz] -= '9';
if (buhe[yz]<0)
buhe[yz] += '9';
}
}*/