السلام عليكم ورحمه الله وبركاته
كل عام وانتم بخير
معى كود لمشروع كان قد ساعدنى فيه اخى (م/حسن هادى محمود ) منذ فتره تتعدى السنه والنصف
وكان الكود عباره عن مشروع امان لفتح باب
ومن ضمن مستويات الامان فيه
عند تغيير باسورد الادمن للمشروع (ادمن الامان )
يطلب الجهاز (المايكروكنترولر) منى الاجابه على سؤال امان
واجابه سؤال الامان من المفترض اننى كتبتها فى الكود ولكن مكتوبه كالتالى
كود:
char security[]={8,19,5,6,12,17,14,14,12};
وكل رقم معوض به بحروف معينه
وكنا كانت الاجابه (itfgmroom)
وكان هناك خاصيه بالكود عند تشغيله وهو عندما اضغط 0 لمده اكثر من 5 ثوانى
يعرض لي اجابه السؤال عباره عن ارقام ومن المفترض حل شفره الارقام التى ستظهر لتحول الى رقم المفروض الناتج ده هو اجابه سؤال الامان
وهنا يظهر لى ارقام 239061886
والمشكله هنا اننى نسيت طريقه حل الشفره دى ومهندس حسن راسلته ولكنه لم يدخل الى المنتدى منذ فتره
فهل احد يساعدى فى تحليل الكود ومعرفه طريقه فك الشفره
الكود هو
كود:
#define led_open portc.f0
#define led_open_dir trisc.f0
#define trans portc.f4
#define trans_dir trisc.f4
#define led_alarm portc.f2
#define led_alarm_dir trisc.f2
#define led_closed portc.f1
#define led_closed_dir trisc.f1
#define input 1
#define output 0
#define on 1
#define off 0
#define is ==
////////////////////////////////////////////
// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;
char keypadPort at PORTD;
//////////////////////////////////variable/////////////
char kp=0, number=0 ,x=0 , y=0 , pp=0 , state_password=255 ;
const char message_length=16;
char check_password=255 , password=0 , choice=255 ;
unsigned int cont=0, cont1=0 , cont2=0;
char my_txt[message_length], txt[7];
char master[]={4,9,1,9,8,9};
char security[]={8,19,5,6,12,17,14,14,12};
char master_code=0;
char error=0 , error2=0, list=0, list1=0, LL=1 , back1=0;
char admin_code=0;
char equation=0 , security_code=0 , direct=0;
///////////////////////// message ///////////////////////////////
const char welcome[] ="Welcome to F-G-M";
const char check_pass[] ="Check password ";
const char correct_pass[] ="Correct password" ;
const char input_pass[] ="Input password ";
const char new_pass[] ="New password ";
const char uncorrect_pass[] ="Vaild password ";
const char old_password[] ="Old password ";
const char change_password[] ="Password changed";
const char enter[] =" Press enter ";
const char admin[] ="Input admin old ";
const char vaild_admin[] ="Vaild admin ";
const char new_admin[] ="New admin ";
const char admin_changed[] ="Admin is changed";
const char securty_equation[] ="Securty equation";
const char my_name[] ="My name is ? ";
const char loading[] ="LOADING ";
const char master_password[] ="Master code ";
const char press_enter[] =" PRESS ENTER ";
const char closed[] ="**** CLOSED ****";
const char open[] ="**** OPEN ****";
const char clear[] =" ";
/////////// define function /////////////////////////////
char keypad();
char function_password();
void test_password(char address);
void message(const char *rom , char zz);
void timer(unsigned int t);
void input_password_test();
void new_password_test();
void change_password_test();
void tone1();
void tone2();
void tone3();
void melody();
void alarm(char mm,char address2,int time2);
char alarm2(char list2,char address2, char error);
void menua( );
void back();
void start_value();
//////////////////////////////////////////////////////////
void init()
{
ADCON1=6;
GIE_BIT=1;//Global Interrupt Enable bit
T0IE_bit=1;//Timer0 Overflow Interrupt Enable bit
T0IF_bit=0;// Timer0 Overflow Interrupt Flag bit
T0CS_bit=0; // Internal instruction cycle clock (FOSC/4)
PSA_bit=0; // Prescaler is assigned to the Timer0 module
PS2_bit=1;PS1_bit=1;PS0_bit=1; //1 : 256
Lcd_Init();
lcd_cmd(_LCD_CURSOR_OFF);
Keypad_Init();
Sound_Init(&PORTC, 3);
led_open_dir=led_closed_dir=led_alarm_dir=output;
led_open= led_closed=led_alarm=off;
trans=0;
trans_dir=output;
///// master code////
eeprom_write(48,6);// write length for master code =6
for(x=1;x<=6;x++)
{
eeprom_write(48+x,master[x-1]);
}
// security equation
eeprom_write(80,9);// write length for master code =9
for(x=1;x<=9;x++)
{
eeprom_write(80+x,security[x-1]);
}
}
//////////////////////////////////////////////////////////////////////////////
void interrupt()
{
if( T0IF_bit is 1) {cont++;cont1++;cont2++; }
tmr0=0;
T0IF_bit=0;
}
/////////////////////////////////////////////////////////////////////////////
void timer( unsigned int t)
{
tmr0=0; cont1=cont=0;
while(t > cont);
}
//////////////////////////////////////////////////////////////////////////////
void download()
{
message(Welcome,1);
message (loading ,2);
for(x=0;x<5;x++)
{
lcd_chr(2,x+8,'.');
timer(16); //1 second
}
}
void main()
{
init();
download();
while(1)
{
lcd_cmd(1);
led_closed=on;
message(closed,1);
function_password();
if (state_password is 1)
{
lcd_cmd(1);
message(open,1);
trans=on;
led_closed=off;
for(x=0;x<30;x++)
{
led_open=~led_open;
timer(5); //328 msec
}
state_password=255;
trans=off;
}
LL =1;// to input menua function
list=0;// this initial value
list1=0;// this initial value
}
}
///////////////////////// show message ////////////////////
void message(const char *message,char zz)
{
for(x=0;x<16;x++) my_txt[x]=message[x];
lcd_out(zz,1,my_txt);
}
////////////////////////char keypad()///////////////////////////////////
char keypad(char state)
{
kp=0;number=0;
while(1)
{
if( state is 1){ tmr0=cont=cont1=0;}
kp=Keypad_Key_Click();
if( kp is 1 ) number=7;
else if( kp is 2 ) number=4;
else if( kp is 3 ) number=1;
else if( kp is 5 ) number=8;
else if( kp is 6 ) number=5;
else if( kp is 7 ) number=2;
else if( kp is 8 ) number=0;
else if( kp is 9 ) number=9;
else if( kp is 10 ) number=6;
else if( kp is 11 ) number=3;
else if( kp is 12 ) kp=12;// inter (#)
else if( kp is 4 ) kp=4;// (*): delete number if writing worng number
else if( kp is 13 ) kp=13;
else if( kp is 14 ) kp=14;
else if( kp is 15 ) kp=15;
else if( kp is 16 ) kp=16;
else kp=255;
return kp;
}
}
//////////////////////////////////////////////////////////////////////////
start_value()
{
pp=0; // start value
password=0; // start value
check_password=0; // randam value
state_password=255; // randam value but not = 0 or 1
choice=255;// randam value but not equal=0
master_code=0;
admin_code=0;
equation=0;
for(x=0;x<16;x++) eeprom_write(16+x,0xff);// clear eeprom
for(x=0;x<16;x++) eeprom_write(32+x,0xff);//clear eeprom
for(x=0;x<16;x++) eeprom_write(96+x,0xff);//clear eeprom
}
////////////////////////////////////////////////////////////////////////////////
void menua( )
{
while( LL is 1)
{
keypad(1);
if( list is 0)
{
if( kp is 8 && cont>=70) // press " 0 "
{
y=1;
}
else if( kp !=0 && kp !=4 && kp<=12)direct=1;
}
if( kp is 16 && y is 0 )
{
list++;
direct=0;
if( list is 4) list=3;
list1=list;
}
if( kp is 15 && y is 0 )
{
list--;
direct=0;
if( list is 0 || list is 255 ) list=1;
list1=list;
}
if( list > 0)message(press_enter,2);
if( list is 1 || direct is 1 )
{
message(input_pass,1);
}
else if( list is 2)
{
message(change_password,1); // change password message
}
else if( list is 3)
{
message(admin,1); // change password message
}
if( (kp is 12 && list is 1) || direct is 1)
{
LL=0;
error=eeprom_read(61);
if(error >= 3) {alarm2(1,61,0); error=0;}
else if(cont2 > 9155){alarm2(1,61,0); error=0;}// reset error after 10 minute(cont2=9155)
message(clear,2);// clear message press inter
choice=1;
}
if( kp is 12 && list is 2)
{
error=eeprom_read(62);
if(error >= 3) {alarm2(2,62,0);error=0;}
else if(cont2 > 9155){alarm2(1,61,0); error=0;}// reset error after 10 minute(cont2=9155)
message(clear,2);// clear message inter
message(old_password,1);
timer( 16); //1 second
LL=0;
choice=0;
}
if( kp is 12 && list is 3)
{
LL=0;
error=eeprom_read(63);
if(error >= 3) {alarm2(3,63,0);error=0;}
else if(cont2 > 9155){alarm2(1,61,0); error=0;}// reset error after 10 minute(cont2=9155)
choice=0;
message(clear,2);//clear message inter
}
if( kp is 13 || direct is 2 )
{
back1=1;
direct=0;
timer( 3); //200 msec
choice =255;
LL=0;//exit from menua
return;
}
if(y is 1 || y is 2)
{
if(kp is 15){message(clear,2);y=1;}
if( kp is 16) {message(clear,2);
y=2;}
if(y is 2)
{
message (master_password,1);
for(x=1;x<=6;x++)
{
txt[x]=(eeprom_read(48+x)+64)/100;
txt[x]=((eeprom_read(48+x)+64)%100)/10;
txt[x]=(eeprom_read(48+x)+64)%100%10;
lcd_chr(2,x,txt[x]+48);
}
}
else if ( y is 1)
{
message (securty_equation,1);
for(x=1;x<=9;x++)
{
txt[x]=(eeprom_read(80+x)+64)/100;
txt[x]=((eeprom_read(80+x)+64)%100)/10;
txt[x]=(eeprom_read(80+x)+64)%100%10;
lcd_chr(2,x,txt[x]+48);
}
}
}
if(kp is 4 && y> 0)
{
LL=0;
back1=1;
y=0;
}
}
}
void back()
{
if( kp is 13 )
{
LL=1;
back1=0;
if( direct is 1)
{
direct=2;
LL=0;
back1=1;
}
choice=255;
start_value();// reset all parameter
}
}
char function_password()
{
start_value();
///////////////////////////////////////////////////////////////////
while(1)
{
if (LL is 1)menua();
if( back1 is 1) { back1=0;return;}
keypad(1);
back();
if(choice is 1 )
{
input_password_test();
if(state_password is 1)
{
lcd_cmd(1);
return state_password;
}
}
else if( choice is 0 && check_password is 0)new_password_test();
else if(check_password is 1)
{
change_password_test();
if( (password is 4 && list is 2) || (password is 4 && security_code is 1 && list is 3))
{
start_value();
lcd_out(1,7,"OK");
timer(23); //1.5 second
lcd_cmd(1);
LL=1;
list=list1;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
void test_password(char address)
{
if(kp is 4 && pp>0)// cancel password
{
pp--;
eeprom_write(address,pp);
lcd_chr(2,pp+1,' ');
}
else if(kp !=4 && kp!=255)
{
if(pp< 15) // passaword length max. 15 can be change and one for store number of password
{
pp++;
if(equation is 0) {lcd_chr(2,pp,'*'); }
else if(equation is 1)
{
if(number is 2)number=12;
if(number is 4)number=14;
if(number is 7)number=17;
if(number is 9)number=19;
lcd_chr(2,pp,number+97);
}
eeprom_Write( (pp+address),number); //must be write pp for write address start from 1
eeprom_write(address,pp);
}
}
}
///////////////////////////////////////////////////////////////////////////////
void input_password_test()
{
if(kp !=12 )// password before change
{
test_password(16);
}
//////////// test password input with original password//////////
while(kp is 12 && eeprom_read(16)>0) // if switch(#) enter is pressed
{
message( input_pass,1);
for(x=0;x<=eeprom_read(16);x++)
{
if( (eeprom_read(x+16)is eeprom_read(x)) ) state_password=1;
else {
state_password=0;
break; // password vaild and exit from for
}
}
if( state_password is 1)
{
alarm2(1,61,0);
lcd_cmd(1);
message(correct_pass,1);
timer(16); //1 second
}
else if ( state_password is 0 )
{
error++;
cont2=0;// time for reset error
state_password=255;// random value but not equal 0 or 1
lcd_cmd(1);
message(uncorrect_pass,1);
timer( 16); //1 second
alarm2(1,61,error);
if(error2 >=3)alarm(1,61,4578);// alarm for 5 minute( cont=4578)
lcd_cmd(1);
message( input_pass,1);
}
pp=0;
kp=255; // exit from while because now kp=12
}
}
///////////////////////////////////////////////////////////////////////////////
void new_password_test()
{
if( kp < 12 )// password before change
{
test_password(16);
}
//////////// test password input with original password//////////
while(kp is 12 && ( password is 0 || admin_code is 0) && eeprom_read(16)> 0) // if switch(#) enter is pressed
{
for(x=0;x<=eeprom_read(16);x++)
{
if( list is 2 && (eeprom_read(x+16)is eeprom_read(x) )) password=1;
else { password=0; break;}// password vaild and exit from for
}
for(x=0;x<=eeprom_read(16);x++)
{
if( ( eeprom_read(x+16)is eeprom_read(x+64)) ) admin_code=1;
else { admin_code=0; break;}// password vaild and exit from for
}
for(x=0;x<=eeprom_read(16);x++)
{
if( (eeprom_read(x+16)is eeprom_read(48+x)) ) master_code=1;
else { master_code=0; break;}// password vaild and exit from for
}
if (password is 0&& master_code is 0 && admin_code is 0 )
{
error++;
cont2=0;// time for reset error
lcd_cmd(1);
if(list is 2)
{
message(uncorrect_pass,1);
alarm2(2,62,error);
}
if(list is 3)
{
message(vaild_admin,1);
alarm2(3,63,error);
}
if(error2 is 3 )
{
if(list is 2)alarm(2,62,916); // alarm for 1 minute( cont=916)
if(list is 3)alarm(2,63,916); // alarm for 1 minute
}
timer( 16); //1 second
lcd_cmd(1);
if(list is 2)message(old_password,1);
if(list is 3)message(admin ,1);
state_password=255;// random value but not equal 0 or 1
}
if( password is 1 || master_code is 1 || admin_code is 1 )
{
if(list is 2){ error=0;alarm2(2,62,0);}// clear error
if(list is 3){ error=0;alarm2(2,62,0);}//clear error
check_password =0;
lcd_cmd(1);
if(list is 2)message(new_pass ,1);
if(list is 3)message(new_admin ,1);
timer( 16); //1 second
admin_code=2;
master_code=2;//this using for exit form condition if( (password is 1 || master_code is 1)&& check_password is 0)
password=2;// this using for exit form condition if( (password is 1 || master_code is 1)&& check_password is 0)
}
kp=255;// because now kp=12 and condition if( kp is 12 && password is 2) password=3; is active
pp=0;
}
if(kp is 12 && password is 2 )
{
lcd_cmd(1);
message(check_pass,1); //check password message
timer( 16); //1 second
check_password=1;
kp=255;// because now kp=12
pp=0;
}
}
////////////////////////////////////////////////////////////////////////////////
void change_password_test()
{
if(kp !=12 && password is 2 && equation is 0 )
{
test_password(32);
}
if( list is 2 && kp is 12) password=3;
if(list is 3 && kp is 12 && equation is 0)
{
equation=1;
lcd_cmd(1);
message(securty_equation ,1);
timer( 16); //1 second
message(my_name ,1);
kp=255;
pp=0;
}
if(equation is 1 && kp<12 )
{
test_password(96);
}
if(equation is 1 && kp is 12)password=3;
while( kp is 12 && password is 3 ) // if switch(#) enter is pressed
{
if(equation is 1)
{
for(x=0;x<=eeprom_read(96);x++)
{
if( eeprom_read(x+96) is eeprom_read(80+x) )security_code=1;
else {security_code =0; break;}
}
}
for(x=0;x<=eeprom_read(16);x++)
{
if( eeprom_read(x+16) is eeprom_read(32+x) )password=4;
else{password=5; break;}
}
if( (password is 5 && equation is 0) || ( password is 5 || (security_code is 0 && equation is 1)) )
{
error++;
cont2=0;// time for reset error
lcd_cmd(1);
if(list is 2)
{
message(uncorrect_pass ,1);
alarm2(2,62,error);
}
if(list is 3)
{
message(vaild_admin ,1);
alarm2(3,63,error);
}
equation=0;
security_code= 0;
password=2;
check_password=0;// back to function new password and start form if(kp !=12 && kp !=255 && password is 2)
if(error2 is 3 )
{
if(list is 2)alarm(2,62,916); // alarm for 1 minute
if(list is 3)alarm(2,63,916); // alarm for 1 minute
}
timer( 16); //1 second
lcd_cmd(1);
if(list is 2)message(new_pass ,1);// new password message
if(list is 3)message(new_admin ,1);
}
pp=0;
kp=255;
}
if( (password is 4 && list is 2) || (password is 4 && security_code is 1 && list is 3))
{
if(list is 2){ error=0;alarm2(2,62,0);}// clear error
if(list is 3){ error=0;alarm2(2,62,0);}//clear error
if( list is 2) for(x=0;x<=eeprom_read(16);x++)eeprom_write(x,eeprom_read(x+16));
else if( list is 3)for(x=0;x<=eeprom_read(16);x++)eeprom_write(x+64,eeprom_read(x+16));
lcd_cmd(1);
if(list is 2)message(change_password ,1);// change password message
if(list is 3)message(admin_changed ,1);
timer( 16); //1 second
lcd_cmd(1);
return ;
}
}
///////////////////////////////////////////////////////////////////////////////
void tone1()
{
sound_play ( 659, 250 ) ;
}
void tone2()
{
sound_play ( 698, 250 ) ;
}
void Tone3()
{
sound_play ( 784, 250 ) ;
}
void melody()
{
tone1(); tone2(); tone3(); tone3();
tone1(); tone2(); tone3(); tone3();
tone1(); tone2(); tone3();
tone1(); tone2(); tone3(); tone3();
tone1(); tone2(); tone3();
tone3(); tone3(); tone2(); tone2(); tone1();
}
void alarm(char mm,char address2,int time2)
{
char srop_alarm=0;
lcd_out(2,6,"alarm");
tmr0=cont=cont1=0;
led_alarm=on;
while(cont<time2)
{
keypad(0);
if(kp is 4 && cont1 > 77)srop_alarm=1;
if(mm is 1 && srop_alarm is 0 )
{
if(srop_alarm is 0 )melody(); // alarm for minute
}
if(mm is 2 && srop_alarm is 0)
{
if(srop_alarm is 0 )tone1(); // alarm for 1 minute
}
}
led_alarm=off;
error=0;
eeprom_write(address2,0);
}
//////////////////////////////////////////////////////////////////////////////
char alarm2(char list2 , char address2, char error )
{
error2=0;
switch(list2)
{
case 1:{
eeprom_write(address2,error);
}
case 2: {
eeprom_write(address2,error);
}
case 3: {
eeprom_write(address2,error);
}
}
error2=eeprom_read(address2);
return error2;
}
وشكرا واسف للاطاله
لو مش مفهوم المشكله ابلغونى بالتوضيح اكتر