?? main.c
字號:
/*********************************************************************************************
* File: main.c
* Author: embest
* Desc: c main entry
* History:
*********************************************************************************************/
#include "44blib.h"
#include "44b.h"
#include <string.h>
void des(char *source,char *dest,char * inkey, int flg);
int Main(){
char szLogo[17] = "Embest S3CEV40 >";
char key[256]={0};
char source[1024]={0};
int i,cnt,k;
char s[9]={0};
char d[9]={0};//65的原因是一個存放\0
char destination[1024]={0};
char *s_ptr;
int flag;
i=cnt=0;
rSYSCFG=CACHECFG;// Using 8KB Cache//
Port_Init();
Uart_Init(0,115200);
Uart_Select(0); //Select UART0//
// printf interface
Uart_Printf("\n");
Uart_Printf(szLogo);
Uart_Printf("\n");
Uart_Printf("Please input flag to detemine encryption or decryption:");
flag=Uart_GetIntNum();
//Uart_Printf("\n");
Uart_Printf("Please input key:");
Uart_GetString(key);
//Uart_Printf("\n");
Uart_Printf("Please input source:");
Uart_GetString(source);
//Uart_Printf("\n");
//*************************
if(flag==0){
k=0;
s_ptr=source;
//printf("******up loop start****\n");
while(*s_ptr){
cnt=0;
//printf("******down loop start****\n");
while(*s_ptr&&cnt<8){
s[cnt]=*s_ptr;
s_ptr++;
cnt++;
}
//printf("******if start****\n");
if((7-cnt)>0){
for(i=cnt;i<8;i++)
s[i]=32;
}
Uart_Printf("Len=%d\n",strlen(s));
for(i=0;i<strlen(s);i++)
Uart_Printf("%c",s[i]);
Uart_Printf("-----printf s end!\n");
Uart_Printf("des start!\n");
des(s,d,key,flag);//flag=0表示;加密對單個字節加密
Uart_Printf("8字節加密結束!\n");
Uart_Printf("Length=%d\n",strlen(d));
for(i=0;i<strlen(d);i++){
destination[k++]=d[i];
Uart_Printf("%c",d[i]);
}
Uart_Printf("\nprintf d end!\n");
memset(d,0,8);
//Uart_Printf("\n");
}
Uart_Printf("if end!");
}
else {
k=0;
s_ptr=source;
//printf("******up loop start****\n");
while(*s_ptr){
cnt=0;
//printf("******down loop start****\n");
while(*s_ptr&&cnt<8){
s[cnt]=*s_ptr;
s_ptr++;
cnt++;
}
//printf("******if start****\n");
/*if((7-cnt)>0){
for(i=7-cnt;i<8;i++)
s[i]=32;
}*/
Uart_Printf("Len=%d\n",strlen(s));
for(i=0;i<strlen(s);i++)
Uart_Printf("%c",s[i]);
Uart_Printf("printf s end!\n");
Uart_Printf("des start!\n");
des(s,d,key,flag);//flag=1表示;加密對單個字節解密
Uart_Printf("8字節解密結束!");
Uart_Printf("\n");
Uart_Printf("Length=%d",strlen(d));
Uart_Printf("\n");
for(i=0;i<8;i++){
destination[k++]=d[i];
Uart_Printf("%c",d[i]);
}
Uart_Printf("printf d end!\n");
//Uart_Printf("\n");
}
Uart_Printf("\n");
Uart_Printf("else end!");
}
Uart_Printf("加密|解密成功!!!");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -