[VC] C语言3位密码字典生成程序源代码

合集下载

C语言实现数据加密算法

C语言实现数据加密算法

C语言实现数据加密算法数据加密是一种保护信息安全性的重要手段。

在C语言中,有多种方式可以实现数据加密算法。

下面将介绍几种常见的加密算法及其实现原理。

1.凯撒密码凯撒密码是一种简单的替换密码。

它的原理是将明文中的每个字母按照指定的位移量进行替换。

例如,将字母'A'替换成字母'D',字母'B'替换成字母'E',以此类推。

解密过程与加密过程相反。

```c#include <stdio.h>void encrypt(char* message, int key)int i = 0;char ch;while (message[i])ch = message[i];if (ch >= 'A' && ch <= 'Z')ch = ((ch - 'A') + key) % 26 + 'A';}else if (ch >= 'a' && ch <= 'z')ch = ((ch - 'a') + key) % 26 + 'a';}message[i] = ch;i++;}void decrypt(char* message, int key)int i = 0;char ch;while (message[i])ch = message[i];if (ch >= 'A' && ch <= 'Z')ch = ((ch - 'A') - key + 26) % 26 + 'A'; }else if (ch >= 'a' && ch <= 'z')ch = ((ch - 'a') - key + 26) % 26 + 'a'; }message[i] = ch;i++;}int maichar message[100];int key;printf("Enter message: ");fgets(message, sizeof(message), stdin);printf("Enter key: ");scanf("%d", &key);encrypt(message, key);printf("Encrypted message: %s\n", message);decrypt(message, key);printf("Decrypted message: %s\n", message);return 0;```2.DES(数据加密标准)DES是一种对称密钥的分组密码算法。

DES算法的C语言实现

DES算法的C语言实现

DES算法的C语⾔实现利⽤C语⾔实现DES算法,分组密码原理过程很简单,但是在写的过程中检查了好久才发现错误原因,主要有两点:1.在加密过程16轮迭代过程中,最后⼀轮迭代运算后的结果并没有进⾏交换,即C=IP-1(R16,L16),这样做的⽬的是为了加密解密使⽤同⼀个算法2.在S盒的过程中,移位后应该加括号,否则+的优先级⾼于<<,会出错,下⾯是算法源码:1 #include "des.h"2 #include <stdio.h>3 #include <stdlib.h>45const unsigned char IP_table[64] = {658, 50, 42, 34, 26, 18, 10, 2,760, 52, 44, 36, 28, 20, 12, 4,862, 54, 46, 38, 30, 22, 14, 6,964, 56, 48, 40, 32, 24, 16, 8,1057, 49, 41, 33, 25, 17, 9, 1,1159, 51, 43, 35, 27, 19, 11, 3,1261, 53, 45, 37, 29, 21, 13, 5,1363, 55, 47, 39, 31, 23, 15, 714 };1516const unsigned char IPR_table[64] = {1740, 8, 48, 16, 56, 24, 64, 32,1839, 7, 47, 15, 55, 23, 63, 31,1938, 6, 46, 14, 54, 22, 62, 30,2037, 5, 45, 13, 53, 21, 61, 29,2136, 4, 44, 12, 52, 20, 60, 28,2235, 3, 43, 11, 51, 19, 59, 27,2334, 2, 42, 10, 50, 18, 58, 26,2433, 1, 41, 9, 49, 17, 57, 2525 };2627const unsigned char E_table[48] = {2832, 1, 2, 3, 4, 5,294, 5, 6, 7, 8, 9,308, 9, 10, 11, 12, 13,3112, 13, 14, 15, 16, 17,3216, 17, 18, 19, 20, 21,3320, 21, 22, 23, 24, 25,3424, 25, 26, 27, 28, 29,3528, 29, 30, 31, 32, 136 };3738const unsigned char P_table[32] = {3916, 7, 20, 21, 29, 12, 28, 17,401, 15, 23, 26, 5, 18, 31, 10,412, 8, 24, 14, 32, 27, 3, 9,4219, 13, 30, 6, 22, 11, 4, 2543 };4445const unsigned char PC1_table[56] = {4657, 49, 41, 33, 25, 17, 9,471, 58, 50, 42, 34, 26, 18,4810, 2, 59, 51, 43, 35, 27,4919, 11, 3, 60, 52, 44, 36,5063, 55, 47, 39, 31, 23, 15,517, 62, 54, 46, 38, 30, 22,5214, 6, 61, 53, 45, 37, 29,5321, 13, 5, 28, 20, 12, 454 };5556const unsigned char LOOP_table[16] = {571, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 158 };5960const unsigned char PC2_table[48] = {6114, 17, 11, 24, 1, 5,623, 28, 15, 6, 21, 10,6323, 19, 12, 4, 26, 8,6416, 7, 27, 20, 13, 2,6541, 52, 31, 37, 47, 55,6630, 40, 51, 45, 33, 48,6744, 49, 39, 56, 34, 53,6846, 42, 50, 36, 29, 3269 };7071const unsigned char sbox[8][4][16] = {72// S17314, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,740, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,754, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,7615, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,77//S27815, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,793, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,800, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,8113, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,82//S38310, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,8413, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,8513, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,861, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,87//S4887, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,8913, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,9010, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,913, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,92//S5932, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,9414, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,954, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,9611, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,97//S69812, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,9910, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,1009, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,1014, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,102//S71034, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,10413, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,1051, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,1066, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,107//S810813, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,1091, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,1107, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,1112, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11112 };113114void ByteToBit(unsigned char* out, const unsigned char* in, const int bits){115for(int i=0;i<bits;i++)116out[i]=(in[i/8]>>(7-i%8))&1;117 }118119void BitToByte(unsigned char* out, const unsigned char* in, const int bits){120 memset(out, 0, (bits + 7) / 8);121for(int i=0;i<bits;i++)122out[i/8]|=in[i]<<(7-i%8);123 }124125void Transform(unsigned char* out,const unsigned char* in, const unsigned char* table, const int len){ 126 unsigned char tmp[64] = {0};127for (int i = 0; i < len; i++)128 tmp[i] = in[table[i] - 1];129 memcpy(out, tmp, len);130 }131132void RotateL(unsigned char* in, const int len, int loop){133static unsigned char tmp[64];134 memcpy(tmp, in, len);135 memcpy(in, in + loop, len - loop);136 memcpy(in + len - loop, tmp, loop);137 }138139static unsigned char subKey[16][48] = { 0 };140void setKey(const unsigned char* in){141char key[64] = { 0 };142 ByteToBit(key, in, 64);143char temp[56]={0};144 Transform(temp, key, PC1_table, 56);145for(int i=0;i<16;i++){146 RotateL(temp, 28, LOOP_table[i]);147 RotateL(temp + 28, 28, LOOP_table[i]);148 Transform(subKey[i], temp, PC2_table, 48);149 }150 }151152void xor(unsigned char* in1,const unsigned char* in2,int len){153for(int i=0;i<len;i++)154 in1[i]^=in2[i];155 }156157void sbox_exchange(unsigned char* out,const unsigned char* in){158char row, column;159for (int i = 0; i < 8; i++){160char num = 0;161 row = (in[6 * i]<<1)+ in[6 * i + 5];162 column = (in[6 * i + 1] << 3) + (in[6 * i + 2] << 2) + (in[6 * i + 3] << 1) + in[6 * i + 4]; 163 num = sbox[i][row][column];164for (int j = 0; j < 4; j++)165 {166out[4 * i + j] = (num >> (3 - j)) & 1;167 }168 }169 }170171void F_func(unsigned char* out,const unsigned char* in,unsigned char* subKey){172 unsigned char temp[48]={0};173 unsigned char res[32]={0};174 Transform(temp, in, E_table, 48);175 xor(temp,subKey,48);176 sbox_exchange(res,temp);177 Transform(out, res, P_table, 32);178 }179180void encryptDES(unsigned char* out,const unsigned char* in, const unsigned char* key){ 181 unsigned char input[64] = { 0 };182 unsigned char output[64] = { 0 };183 unsigned char tmp[64] = { 0 };184 ByteToBit(input, in, 64);185 Transform(tmp, input, IP_table, 64);186char* Li = &tmp[0], *Ri = &tmp[32];187 setKey(key);188for(int i=0;i<16;i++){189char temp[32]={0};190 memcpy(temp,Ri,32);191 F_func(Ri, Ri,subKey[i]);192 xor(Ri, Li, 32);193 memcpy(Li,temp,32);194 }195 RotateL(tmp, 64, 32);//the input is LR,output is RL196 Transform(output, tmp, IPR_table, 64);197 BitToByte(out, output,64);198 }199200void decryptDES(unsigned char* out,const unsigned char* in, const unsigned char* key){ 201 unsigned char input[64] = { 0 };202 unsigned char output[64] = { 0 };203 unsigned char tmp[64] = { 0 };204 ByteToBit(input, in, 64);205 Transform(tmp, input, IP_table, 64);206char* Li = &tmp[0], *Ri = &tmp[32];207 setKey(key);208 RotateL(tmp, 64, 32);209for (int i = 0; i < 16; i++){210char temp[32] = { 0 };211 memcpy(temp, Li, 32);212 F_func(Li, Li,subKey[15 - i]);213 xor(Li, Ri, 32);214 memcpy(Ri, temp, 32);215 }216 Transform(output, tmp, IPR_table, 64);217 BitToByte(out, output, 64);218 }。

单片机密码锁C程序完整代码

单片机密码锁C程序完整代码

单片机密码锁C程序完整代码2009-08-18 14:39#include<AT89x51.h>#include"intrins.h"#include"key.h"#include"xsh.h"#include"24c02.h"#define ulong unsigned longbit BJCB=0;//报警标志XG=0,//修改密码标志位BJ=0,//报警标志位SJ=0;//锁键盘标志位// xg=0;//修改密码标志位uchar PSWD0_0[16]={0};//密码输入缓存存储单元//uchar code PSWD0_1[16]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};//用户初始密码存储单元//uchar PSWD1_0[16]={0};//读出密码缓存存储单元uchar PSWD1_1[16]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8};//管理员初始密码存储单元sbit OUT=P3^5;//输出端口sbit L1=P0^2;//上电指示sbit L2=P0^1;//开锁指示sbit L3=P0^0;//报警指示uint mg=0,//密码个数KSC=0,//开锁次数BJC=0,//报警次数TCNTY=0,//用户按键定时次数累加TCNTG=0,//管理员输入密码定时次数yhsh,//用户输入标志位glsh,//管理员输标志位shw;//密码输完标志位void yhmimaxig();//密码修改程序void glmimaxig();//管理员修改程序void bjyin(ulong t){ulong c;uint n;for(c=0;c<t;c++){for(n=0;n<50;n++); //延时BEEP=~BEEP; //取反输出到喇叭的信号}}void delay_10ms(void){uint i = 1000;while(i--);}//////////////定时中断服务函数////////////////////////////////////// void timer0() interrupt 1{uint i;TH0=(65536-50000)/256; //对TH0 TL0赋值50MS定时TL0=(65536-50000)%256; //重装计数初值if(yhsh==1){TCNTY++;//用户定时计数if(shw==1){TR0=0;TCNTY=0;}if(TCNTY==200){TR0=0;//关闭T0定时器TCNTY=0;mg=0;//密码个数清零L1=1;for(i=0;i<2;i++)//声光报警电路{L3=0;bjyin(1000);L3=1;delay(1000);}L1=0;}}else if(glsh==1){TCNTG++;//管理员定时计数if(shw==1){TR0=0;TCNTG=0;}if(TCNTG==160){TR0=0;//关闭T0定时器TCNTG=0;mg=0;//密码个数清零L1=1;for(i=0;i<2;i++)//声光报警电路{L3=0;bjyin(1000);L3=1;delay(1000);}L1=0;}}}void main(){uint i;TMOD=0x01; //定时器工作在方式1ET0=1;EA=1;TH0=(65536-50000)/256; //对TH0 TL0赋值TL0=(65536-50000)%256; //使定时器0.05秒中断一次//Read_page24c02(0x00,PSWD1_1,16);//向24c02里读用户初始密码 //i2cWrite24LC16B(0,0X20);/////////////第一次向24c02里写入初始管理员密码、用户密码、开锁次数/////////////////////KSC=i2cRead24LC16B(0X20);loop: L1=0;//上电红灯亮L2=1;//开锁成功后绿灯亮L3=1;//输错时黄灯亮报警OUT=0;//开信号关闭display_0(KSC);//开锁前显示///////////密码输入/////////////////if(SJ==0)//锁键盘标志位为0{do{flag=0;//键盘标志位key();if(flag==1&&num==12) //判断是否为管理员功能键按下{goto gl;}if(flag==1&&num<=9){PSWD0_0[mg]=num;mg++;//密码个数}if(flag==1&&num==14&&mg>=1)//输入错误删除{mg=mg-1;}if(mg==1) //有密码键按下开定时器限时{TR0=1;yhsh=1;}}while(num!=15);if(mg!=16){for(i=mg;i<16;i++){PSWD0_0[i]=0;}}/////////////////密码比较电路//////////////////////////// if(flag==1&&num==15){ flag=0;yhsh=0;shw=1;num=0;for(i=0;i<16;i++) //从24c02里读出16个密码{PSWD1_1[i]=i2cRead24LC16B(i);delay_10ms;}for(i=0;i<16;i++){if(PSWD1_1[i]!=PSWD0_0[i]){BJCB=1;break;}else}}if(BJCB!=0){BJC++;if(BJC!=3){BJCB=0; //第一次和第二次报警delay(500);mg=0;//密码个数清零L1=1;for(i=0;i<3;i++)//声光报警电路{L3=0;display_3();bjyin(1000);L3=1;delay(1000);}goto loop;}else if(BJC==3){BJC=0;BJCB=0;display_5();//三次输入密码失败,自锁SJ=1;//锁键盘标志位mg=0;//密码个数清零L1=1;for(i=0;i<2;i++)//声光报警电路{L3=0;bjyin(1000);L3=1;delay(1000);}goto loop;}}elseif(BJCB==0){display_1(KSC);i2cWrite24LC16B(KSC,0X20);if(KSC==100){SJ=1;}L2=0;L1=1;OUT=1;mg=0;//密码个数清零loop1:do //键盘扫描等待功能键按下{flag=0;key();if(flag){flag=0;switch(num){case 13:{display_2();do{flag=0;//键盘标志位key();if(flag==1&&num<=9){PSWD0_0[mg]=num;mg++;//密码个数}if(flag==1&&num==14&&mg>=1)//输入错误删除{mg=mg-1;}if(mg==16){do //键盘扫描等待功能键按下{flag=0;key();}while(num!=15);}}while(num!=15);if(mg!=16&&num==15){for(i=mg;i<16;i++){PSWD0_0[i]=0;}}if(flag==1&&num==15){flag=0;mg=0;for(i=0;i<16;i++) //用一次写一个向24c02里写{i2cWrite24LC16B(PSWD0_0[i],i);delay_10ms;}display_1(KSC);do //键盘扫描等待功能键按下{flag=0;key();}while(num!=11); //按下返回键,锁锁返回{goto loop;}}};break;case 11: {goto loop;//break;}}}}while(flag!=0);//如果设置密码键按下goto loop1;// i2cWrite24c02_page(0x00,PSWD1_1,mg);}}else{do{flag=0;key();}while(num!=12);//判断是否为管理员功能键按下gl:do//管理员输入密码{flag=0;key();if(flag==1&&num<=9){PSWD0_0[mg]=num;mg++;//密码个数}if(flag==1&&num==14&&mg>=1)//删除键按下{mg=mg-1;}if(mg==1){TR0=1;}//开定时器TO限5秒开锁}while(num!=15);if(mg!=16&&num==15){for(i=mg;i<16;i++){PSWD0_0[i]=0;}}//////////管理员密码比较/////////////////////// //Read_page24c02(0x10,PSWD0_1,16)for(i=0;i<16;i++) //从24c02里读出16个密码{PSWD1_1[i]=i2cRead24LC16B((0x10+i));delay_10ms;}if(flag==1&&num==15){ flag=0;shw=1;num=0;for(i=0;i<mg;i++){if(PSWD1_1[i]!=PSWD0_0[i]){ BJCB=1;break;}elseBJCB=0;}}if(BJCB!=0){BJC++;if(BJC!=3){BJCB=0; //第一次和第二次报警mg=0;//密码个数清零L1=1;for(i=0;i<2;i++)//声光报警电路{L3=0;display_3();bjyin(1000);L3=1;delay(1000);}display_1(KSC);goto loop;}else{BJCB=0;display_5();//三次输入密码失败,自锁mg=0;//密码个数清零delay(10000);display_1(KSC);goto loop;}}else{SJ=0;display_4();//管理员开锁显示mg=0;L2=0;L1=1;L3=0;//密码个数清零do //键盘扫描等待功能键按下{flag=0;key();}while(flag==0); //如果设置密码键按下if(flag==1&&num==13){flag=0;display_2();do{flag=0;//键盘标志位key();if(flag==1&&num<=9){PSWD0_0[mg]=num;mg++;//密码个数}if(flag==1&&num==14&&mg>=1)//输入错误删除 {mg=mg-1;}if(mg==16){do //键盘扫描等待功能键按下{flag=0;key();}while(num!=15);}}while(num!=15);if(mg!=16&&num==15){for(i=mg;i<16;i++){PSWD0_0[i]=0;}}if(flag==1&&num==15){flag=0;mg=0;for(i=0;i<16;i++) //用一次写一个向24c02里写{i2cWrite24LC16B(PSWD0_0[i],(0x10+i));delay_10ms;}display_4();do //键盘扫描等待功能键按下{flag=0;key();}while(num!=11); //按下返回键,锁锁返回{goto loop;}}}if(flag==1&&num==10){KSC=0;i2cWrite24LC16B(KSC,0X20);display_1(KSC);do //键盘扫描等待功能键按下{flag=0;key();}while(num!=11);//按下返回键,锁锁返回goto loop;}if(flag==1&&num==11)//按下返回键,锁锁返回{goto loop;}}}}#ifndef _key_h#define _key_h#include<AT89x51.h>#define uchar unsigned char#define uint unsigned intbit flag=0;//按键按下标志位sbit BEEP=P3^7;//蜂鸣器端口delay(int z)//延时1ms{ int x,y;for (x=z;x>0;x--)for (y=140;y>0;y--);}uchar num;//按键返回值////////按键音程序////////////////// void yin(){int c,n;if(flag==1){for(c=0;c<80;c++){for(n=0;n<50;n++); //延时BEEP=~BEEP; //取反输出到喇叭的信号}}}////////////键盘程序/////////////////// int key(){ uchar temp;P2=0X7f;temp=P2&0x0f;if(temp!=0x0f){delay(5);if(temp!=0x0f){temp=P2;switch(temp){ case 0x77:num=0;break;case 0x7b:num=1;break;case 0x7d:num=2;break;case 0x7e:num=3;}do{ //等待按键抬起 temp=P2;temp=temp&0x0f;}while(temp!=0x0f);flag=1;yin();}}P2=0Xbf;temp=P2&0x0f;if(temp!=0x0f){delay(5);if(temp!=0x0f){temp=P2;switch(temp){ case 0xb7:num=4;break;case 0xbb:num=5;break;case 0xbd:num=6;break;case 0xbe:num=7;break;}do{temp=P2;temp=temp&0x0f;}while(temp!=0x0f);flag=1;yin();}}P2=0Xdf;temp=P2&0x0f;if(temp!=0x0f){delay(5);if(temp!=0x0f){temp=P2;switch(temp){ case 0xd7:num=8;case 0xdb:num=9;break;case 0xdd:num=10;break;case 0xde:num=11;break;}do{temp=P2;temp=temp&0x0f;}while(temp!=0x0f);flag=1;yin();}}P2=0Xef;temp=P2&0x0f;if(temp!=0x0f){delay(5);if(temp!=0x0f){temp=P2;switch(temp){ case 0xe7:num=12;break;case 0xeb:num=13;break;case 0xed:num=14;break;case 0xee:num=15;break;}do{temp=P2;temp=temp&0x0f;}while(temp!=0x0f);flag=1;yin();}}return(num);}#endif#ifndef _xsh_h#define _xsh_h#include<AT89x51.h>#define uchar unsigned char#define uint unsigned intsbit shj=P1^0;//串口数据口sbit sck=P1^1;//串口时钟uchar code tab[20]={ 0x88,/*0*/0xBE,/*1*/0xC4,/*2*/0x94,/*3*/0xB2,/*4*/0x91,/*5*/0x81,/*6*/0xBC,/*7*/0x80,/*8*/0x90,/*9*/0xA0,/*A*/0x83,/*b*/0xC9,/*C*/0x86,/*d*/0xC1,/*E*/0xE1,/*F*/0xA8,/*N*/0xF7,/*-*/0x94,/*反E*/0xE0/*P*/ }; //共阳数码管uchar code sb0[3]={8,8,8},/*开锁后显示*/code sb1[3]={0,15,15},/*开锁前显示*/code sb2[6]={17,17,17,17,17,17},/*修改显示*/code sb3[6]={16,0,16,0,16,0},/*第一二次报警显示*/ code sb4[6]={8,8,8,8,8,8},/*管理员进入显示*/code sb5[6]={18,18,18,18,18,18};/*第三次报警显示*///////////////////////////*显示电路*///////////////////////// void writedata(uchar num)//传送一个字节{uchar temp;int i;temp=tab[num];for(i=0;i<8;i++){ temp=temp<<1;shj=CY;sck=0;sck=1;}}void display_0(uchar temp)//开锁前状态{ int i,g,s,q;uchar m;q=temp/100;s=temp%100/10;g=temp%10;for(i=0;i<3;i++){m=sb1[i];writedata(m);}writedata(q);writedata(s);writedata(g);}void display_1(uchar temp)//开锁后状态{int i,g,s,q;uchar m;q=temp/100;s=temp%100/10;g=temp%10;for(i=0;i<3;i++){m=sb0[i];writedata(m);}writedata(q);writedata(s);writedata(g);}void display_2()//修改密码显示{int i;uchar m;for(i=0;i<6;i++){m=sb2[i];writedata(m);}}void display_3()//报警显示{int i;uchar m;for(i=0;i<6;i++){m=sb3[i];writedata(m);}}void display_4()//管理员模式显示{int i;uchar m;for(i=0;i<6;i++){m=sb4[i];writedata(m);}}void display_5()//管理员模式显示{int i;uchar m;for(i=0;i<6;i++){m=sb5[i];writedata(m);}}#endif#ifndef _24c02_h#define _24c02_h#include<AT89x51.h>#define WriteDeviceAddress 0xa0#define ReadDeviceAddress 0xa1sbit SDA=P1^5;//I2C数据端sbit SCL=P1^6;//I2C时钟端///////////////////////24C0224C08读写驱动程序///////////////////////void DelayMs(unsigned int number) {unsigned char temp;for(;number>=1;number--){for(temp=112;temp>=1;temp--) ;}}void i2cStart(void){SDA=1;SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();SDA=0;_nop_();_nop_();_nop_();_nop_();_nop_();SCL=0;}void i2cStop(void){SDA=0;SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();SDA=1;_nop_();_nop_();_nop_();_nop_();_nop_();}void i2cAck(void){SDA=0;SCL=1;_nop_();_nop_();_nop_();_nop_();SDA=1;SCL=0;}void i2cNoAck(void){SDA=1;SCL=1;_nop_();_nop_();_nop_();_nop_();SDA=0;SCL=0;}void i2cWrite8Bit(unsigned char input) {unsigned char temp;for(temp=8;temp!=0;temp--){SDA=(bit)(input&0x80);SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();SCL=0;input=input<<1;}DelayMs(20);}unsigned char i2cRead8Bit(void){unsigned char temp,rbyte=0;for(temp=8;temp!=0;temp--){SCL=1;_nop_();_nop_();_nop_();rbyte=rbyte<<1;rbyte=rbyte|((unsigned char)(SDA));SCL=0;}return(rbyte);}void i2cWrite24LC16B(unsigned char wdata,unsigned char RomAddress) {i2cStart();i2cWrite8Bit(WriteDeviceAddress);i2cAck();i2cWrite8Bit(RomAddress);i2cAck();i2cWrite8Bit(wdata);i2cAck();i2cStop();DelayMs(20);}//写入多个字节到24c02中//传入参数:地址、待写入的数据的首地址、数据长度bit i2cWrite24c02_page(uchar RomAddress,uchar *WRdata,uchar length) {uint i;i2cStart();i2cWrite8Bit(WriteDeviceAddress);i2cAck();i2cWrite8Bit(RomAddress);i2cAck();for(i=0;i<length;i++){i2cWrite8Bit(*WRdata);i2cAck();WRdata++;}i2cStop();DelayMs(20);return(1);}unsigned char i2cRead24LC16B(unsigned char RomAddress){unsigned char x;i2cStart();i2cWrite8Bit(WriteDeviceAddress);i2cAck();i2cWrite8Bit(RomAddress);i2cAck();i2cStart();i2cWrite8Bit(ReadDeviceAddress);i2cAck();_nop_();_nop_();_nop_();x=0;x=i2cRead8Bit();i2cNoAck();i2cStop();return(x);}//从24c02中读出多个字节bit Read_page24c02(uchar RomAddress,uchar p[],uint n) { uint i;i2cStart();i2cWrite8Bit(WriteDeviceAddress);i2cAck();i2cWrite8Bit(RomAddress);i2cAck();i2cStart();i2cWrite8Bit(ReadDeviceAddress);i2cAck();_nop_();_nop_();_nop_();for(i=0;i<n-1;i++){p[i]=i2cRead8Bit();i2cAck();}p[n-1]=i2cRead8Bit();i2cNoAck();i2cStop();return(1);}。

c语言逆序的三位数程序

c语言逆序的三位数程序

c语言逆序的三位数程序C语言是一种非常常用的编程语言,它提供了许多强大的功能和灵活的语法,可以用来解决各种问题。

本文将介绍一个以C语言编写的逆序的三位数程序。

我们来了解一下逆序的概念。

逆序是指将原有的顺序颠倒过来,比如将123逆序就是321。

在这个程序中,我们要实现的就是输入一个三位数,然后将其逆序输出。

在C语言中,可以使用以下的代码来实现这个功能:```c#include <stdio.h>int main() {int num, reversed_num = 0;printf("请输入一个三位数:");scanf("%d", &num);while (num != 0) {int remainder = num % 10;reversed_num = reversed_num * 10 + remainder;num /= 10;}printf("逆序的结果是:%d\n", reversed_num);return 0;}```我们需要定义两个变量`num`和`reversed_num`,分别用来保存用户输入的数字和逆序后的结果。

然后,使用`printf`函数提示用户输入一个三位数,并使用`scanf`函数将输入的值保存到`num`变量中。

接下来,我们使用循环语句`while`来实现逆序操作。

在每一轮循环中,我们通过`num % 10`取出`num`的个位数字,然后将其加入到`reversed_num`的末尾,并且将`num`除以10,去掉个位数字。

循环继续执行,直到`num`变为0,表示所有的位数都已经取出并加入到了`reversed_num`中。

使用`printf`函数输出逆序后的结果。

通过这个简单的程序,我们可以实现对任意一个三位数的逆序操作。

无论输入的数字是多少,这个程序都能正确地将其逆序输出。

总结一下,本文介绍了一个以C语言编写的逆序的三位数程序。

C语言加密与解密算法

C语言加密与解密算法

C语言加密与解密算法在计算机科学与信息安全领域,加密与解密算法起着至关重要的作用。

加密算法用于将原始数据转换为不可读的密文,而解密算法则用于将密文还原为可读的原始数据。

C语言是一种常用的编程语言,具备高效性和灵活性,适用于加密与解密算法的开发。

本文将介绍几种常用的C语言加密与解密算法。

一、凯撒密码算法凯撒密码算法是一种最简单的替换加密算法,通过将字母按照固定的偏移量进行替换来实现加密与解密。

以下是一个简单的C语言凯撒密码实现例子:```c#include <stdio.h>void caesarEncrypt(char* message, int key) {int i = 0;while (message[i] != '\0') {if (message[i] >= 'a' && message[i] <= 'z') {message[i] = (message[i] - 'a' + key) % 26 + 'a';} else if (message[i] >= 'A' && message[i] <= 'Z') {message[i] = (message[i] - 'A' + key) % 26 + 'A';}i++;}}void caesarDecrypt(char* message, int key) {int i = 0;while (message[i] != '\0') {if (message[i] >= 'a' && message[i] <= 'z') {message[i] = (message[i] - 'a' - key + 26) % 26 + 'a'; } else if (message[i] >= 'A' && message[i] <= 'Z') {message[i] = (message[i] - 'A' - key + 26) % 26 + 'A'; }i++;}}int main() {char message[] = "Hello, World!";int key = 3;printf("Original message: %s\n", message);caesarEncrypt(message, key);printf("Encrypted message: %s\n", message);caesarDecrypt(message, key);printf("Decrypted message: %s\n", message);return 0;}```以上程序演示了凯撒密码的加密与解密过程,通过指定偏移量实现对消息的加密与解密。

C语言密码学与加密算法

C语言密码学与加密算法

C语言密码学与加密算法密码学是研究加密和解密技术的学科,它在现代信息安全中扮演着非常重要的角色。

C语言作为一种高效且广泛应用的编程语言,可以用来实现各种密码学算法。

本文将介绍C语言中的一些常用密码学算法及其实现。

一、凯撒密码(Caesar Cipher)凯撒密码是一种简单的替换密码,它通过将字母按照固定的位移量进行替换来进行加密和解密操作。

C语言中可以使用字符数组和循环来实现凯撒密码的加密和解密功能。

以下是一个示例代码:```c#include <stdio.h>#define SHIFT 3void encrypt(char* message) {int i = 0;while (message[i] != '\0') {if (message[i] >= 'a' && message[i] <= 'z') {message[i] = (message[i] - 'a' + SHIFT) % 26 + 'a';}else if (message[i] >= 'A' && message[i] <= 'Z') {message[i] = (message[i] - 'A' + SHIFT) % 26 + 'A';}i++;}}void decrypt(char* message) {int i = 0;while (message[i] != '\0') {if (message[i] >= 'a' && message[i] <= 'z') {message[i] = (message[i] - 'a' - SHIFT + 26) % 26 + 'a'; }else if (message[i] >= 'A' && message[i] <= 'Z') {message[i] = (message[i] - 'A' - SHIFT + 26) % 26 + 'A'; }i++;}}int main() {char message[] = "Hello, World!";encrypt(message);printf("Encrypted message: %s\n", message);decrypt(message);printf("Decrypted message: %s\n", message);return 0;}```二、AES算法(Advanced Encryption Standard)AES算法是目前应用最广泛的对称加密算法之一。

C语言加密解密源程序代码

C语言加密解密源程序代码
//文件加密与解密//
#include<stdio.h>
#include<stdlib.h>
#define M 1000 //预设一个指定文件大小的数字M,方便以后改变
void yiwei() ;
int main()
{
printf("\n$****本程序只能对英文文本进行加密解密操作,如有不便尽请谅解****$");
printf("\n");
printf("\n$******************退出程序输入:1*********************$"); // 欢迎界面
printf("\n");
printf("\n$***************移位加密与解密输入:2******************$"); //
fclose(outfile);
break;
}
printf("\n");
printf("\n*-·-·-感谢您的使用,欢迎再次使用-·-·-*\n\n"); // 使用完感谢语!
exit(0);
}
/*****************调用二进制加密解密函数*********************/
printf(" --> ");
rewind(outfile);
while((data=fgetc(outfile))!=EOF)
printf("%c",data);
printf("\n\n");

c语言字符串加密方式

c语言字符串加密方式

c语言字符串加密方式在C语言中,字符串加密可以通过多种方式实现,这里提供一种简单的加密方式,即凯撒密码(Caesar cipher)加密。

凯撒密码是一种简单的替换密码,它将明文中的每个字符替换为字母表中固定位置后的字符。

例如,如果将字母表中的每个字符向后移动3个位置,那么明文 "hello" 将被加密为 "khoor".下面是一个使用C语言实现凯撒密码加密的示例代码:```cinclude <>include <>include <>void encrypt(char str, int shift) {int len = strlen(str);for (int i = 0; i < len; i++) {char c = tolower(str[i]);if (isalpha(c)) {c = ((c - 'a' + shift) % 26) + 'a';}str[i] = c;}}int main() {char str[100];int shift;printf("Enter a string: ");fgets(str, sizeof(str), stdin);printf("Enter the shift value: ");scanf("%d", &shift);encrypt(str, shift);printf("Encrypted string: %s", str);return 0;}```在这个示例中,我们定义了一个 `encrypt` 函数来执行凯撒密码加密。

该函数接受两个参数:要加密的字符串和移动的位数。

该函数遍历字符串中的每个字符,将其转换为小写字母,并根据移动的位数进行替换。

三位数字识别python代码 opencv

三位数字识别python代码 opencv

三位数字识别是近年来在计算机视觉领域备受关注的一个课题。

在本文中,我将结合我的专业知识和经验,利用Python和OpenCV库来探讨三位数字识别的相关代码实现。

通过深入的分析和详细的步骤说明,希望能够帮助读者更全面地理解这一主题。

1. 三位数字识别的背景和意义三位数字识别在实际应用中具有重要的意义,例如在自动驾驶、智能交通系统、数字识别等方面都有着广泛的应用。

通过对数字图像进行识别,计算机可以实现对数字信息的自动识别和处理,从而极大地提高了工作效率和准确性。

深入研究三位数字识别的相关代码实现具有重要的理论和应用意义。

2. 三位数字识别的代码实现在Python中,使用OpenCV库可以轻松地实现三位数字识别的相关代码。

我们需要准备一个包含多个数字图像的数据集,并对其进行预处理,包括图像的灰度化、二值化、去噪等操作。

利用OpenCV中的模式识别和机器学习算法,可以实现对数字图像的特征提取和分类识别。

针对不同的数字识别场景,可以选择合适的算法和模型,例如KNN、SVM、神经网络等,通过对训练数据集的学习和训练,以及对测试数据集的验证和测试,最终实现对三位数字的准确识别。

3. 个人观点和理解在实际的三位数字识别任务中,除了代码实现之外,还需要考虑图像采集、预处理、模型选择和调参等方面的问题。

随着深度学习和神经网络算法的发展,三位数字识别的性能和准确率也得到了显著提升。

我认为,未来随着技术的不断进步,三位数字识别的相关代码实现将会更加智能化和高效化,为各行各业带来更多的应用和机遇。

4. 总结和回顾通过本文的讨论,我们对三位数字识别的Python代码实现有了更深入的认识。

在实际应用中,我们可以根据具体的需求和场景,选择合适的算法和模型,并结合OpenCV库进行代码的实现和优化。

希望本文能够为读者提供一些有益的参考和启发,激发大家对三位数字识别这一领域的研究和探索。

在本篇文章中,我深入探讨了三位数字识别的Python代码实现,并结合个人观点和理解进行了阐述。

密码词典 密码生成代码,源代码

密码词典 密码生成代码,源代码
if(!strcmp(argv[1],"-ca"))
{
acle(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-u"))
{
turn(argv[2],argv[3]);
}
else
{
for(i=m;i<=n;i++)
fprintf(fp,"%d%d%ld\n",w,p,i);
}
rewind(fp);
while((ch=fgetc(fp))!=EOF)
void acle(char *,char *,char *,char *); /*文件每行删除特定的字符串*/
void cut(char *,char *,char *,char *); /*保留文件每行中特定字符前面的字符串*/
void txt2dic(char *,char *,char *,char *); /*过滤特定字符串*/
txt2dic(argv[2],argv[3],argv[4],argv[5]);
}
if(!strcmp(argv[1],"-g"))
{
grep(argv[2],argv[3],argv[4]);
}
void tel(char *,char *,char *,char *); /*电话密码*/
void create(char *,char *,char *,char *); /*穷举密码*/
void adle(char *,char *,char *,char *); /*文件每行加入特ar *a,char *b,char *c,char *d,char *e) /*手机字典生成函数*/

[VC] C语言3位密码字典生成程序源代码

[VC] C语言3位密码字典生成程序源代码

#include<stdio.h>#include<windows.h>//cls清屏功能函数调用int main(){FILE *fp;int i,j,k,l,m,o,p,q,r,s,t,u,v,w,x,y,n;char d;char *a="00123456789abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU VWXYZ[]~.',/\\:!?@#$%^&*()<>_+|~`{ }-;\"";printf("★**************************************************************★\n");printf("§*******************★欢迎使用密码破解程序系统★*****************§\n");printf("§************************************************** ************§\n");printf("§§§§\n");printf("§§§§\n");printf("§§§§\n");printf("§§☆1 . 启动生成1位密码程序 §§\n");printf("§§☆2 . 启动生成2位密码程序§§\n");printf("§§☆ 3 . 启动生成3位密码程序§§\n");printf("§§§§\n");printf("§§§§\n");printf("★**************************************************************★\n");printf("◆请选择要破译密码的长度(0-6)后按下回车键启动破解程序:\n");scanf("%d",&n);system("cls");switch(n){case 1:{fp=fopen("1位密码字典.txt","w+");for(i=1;i<=97;i++){fprintf(fp,"%c\t",a);}printf("\n");break;}case 2:{fp=fopen("2位密码字典.txt","w+");for(i=1;i<=97;i++){{for(j=1;j<=97;j++)fprintf(fp,"%c%c\t",a,a[j]);}}printf("\n");break;}case 3:{fp=fopen("3位密码字典.txt","w+");for(i=1;i<=97;i++){{for(j=1;j<=97;j++)for(k=1;k<=97;k++)fprintf(fp,"%c%c%c\t",a,a[j],a[k ]);}}printf("\n");break;}default : printf("enter data error!\n");}fclose(fp);printf("%d位密码字典已经生成!\n",n);return 0;}************************************************************** ************************************************************** *************************************************。

C语言加解密算法详解

C语言加解密算法详解

C语言加解密算法详解在当今信息化时代,数据的安全性和保密性变得愈发重要。

为了保护数据免遭不法分子的窃取或篡改,加密算法成为了一种常见的数据保护手段。

C语言作为一种广泛应用的编程语言,也提供了丰富的加解密算法库。

本文将详细介绍C语言中常用的加解密算法,并对其原理进行解析。

1. 凯撒密码凯撒密码是一种简单的字母替换加密算法,它通过将明文中的每个字母按照字母表中的顺序向后(或向前)移动固定的位置来进行加密。

例如,将明文字符'A'移动3个位置后,得到密文字符'D'。

解密时,只需将密文字符反向移动相同位置即可还原为明文字符。

凯撒密码的算法实现非常简单,可以使用C语言中的字符操作函数和条件语句来完成。

以下是一个使用凯撒密码加密字符串的示例代码:```c#include <stdio.h>void caesar_encrypt(char *str, int key) {int i = 0;while (str[i] != '\0') {if (str[i] >= 'A' && str[i] <= 'Z') {str[i] = ((str[i] - 'A') + key) % 26 + 'A';}else if (str[i] >= 'a' && str[i] <= 'z') {str[i] = ((str[i] - 'a') + key) % 26 + 'a';}i++;}}int main() {char str[100] = "Hello, World!";int key = 3;caesar_encrypt(str, key);printf("Encrypted string: %s\n", str);return 0;}```2. DES算法DES(Data Encryption Standard)是一种对称分组密码算法,使用56位的密钥对64位的数据进行加密和解密。

C语言计算器程序源代码

C语言计算器程序源代码

C语⾔计算器程序源代码//strcmp(s1,s2) 当s1⼤于s2时,返回1 ,s1⼩于s2时,返回-1,相等时,返回0 #include "stdio.h"#include "ctype.h"#include "string.h"#include "math.h"#define MAX 256#define STACK_SIZE 128#define WORD_LEN 8#define POP 1#define PUSH 0#define ERR -1#define END 2#define OPER 0#define NUM 1#define WORD 2#define ADD 1#define SUB 2#define MUL 3#define DIV 4#define POW 5#define FAC 6#define BRA_L 7#define BRA_R 8#define SIN 9#define COS 10#define TAN 11#define CTG 12#define LG 13 //以10为底的常⽤对数//#define LN 14//#define LOG 15//⾏标为当前操作符代号,列标为栈顶元素代号//2表⽰计算结束,0表⽰当前操作符进栈,1表⽰栈顶操作符出栈// \0 + - * / ^ ! ( ) sin cos tg ctg lgint Priority[14][14]={2, 1, 1, 1, 1, 1, 1,-1,-1, 1, 1, 1, 1, 1, /* \0 */0, 1, 1, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* + */0, 1, 1, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* - */0, 0, 0, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* * */0, 0, 0, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* / */0, 0, 0, 1, 1, 1, 1, 0,-1, 0, 0, 0, 0, 0, /* ^ */0, 0, 0, 0, 0, 0, 1, 0,-1, 0, 0, 0, 0, 0, /* ! */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* ( */-1,1, 1, 1, 1, 1, 1, 1,-1, 1, 1, 1, 1, 1, /* ) */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* sin */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* cos */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* tg */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* ctg */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0}; /* lg */char KeyWord[36][WORD_LEN+1]={"sin", //前12个为函数,多余的⽤于扩展"cos","tan","tg","ctg","lg","","","","","","","","","","help", // 后⾯为命令,多余的为扩展"version","set","digit", //精度,⼩数点后的位数"color","radian", //弧度"degree", //⾓度"file","clr","clear","window", //窗⼝模式"fullscr", //全屏模式"","","","","","","","",""};int OperCode(char c){int code;switch(c){case '\0':code=0;break;case '+':code=1;break;case '-':code=2;break;case '*':code=3;break;case '/':code=4;break;case '^':code=5;break;case '!':code=6;break;case '(':code=7;break;case ')':code=8;break;case 's':code=9;break; //sincase 'c':code=10;break; //coscase 't':code=11;break; //tgcase 'C':code=12;break; //ctgcase 'l':code=13;break; //log default:code=-1;break;};return code;}int WordCode(char* word){int i;for(i=0;i<25;i++)if(strcmp(KeyWord[i],word)==0) break;if(i>=25)return -1;else}void help(){printf("显⽰帮助信息!\n");return;}void version(){printf("显⽰版本信息!\n");return;}void Err(int errcode,int position,char *p){printf("\n ERR:%d Position:%d %s",errcode,position,p); return;}double long factorial(int i){if(i==1 || i==0)return(1.0);elsereturn(i*factorial(i-1));}main(){char Expression[MAX+1];int Operator[STACK_SIZE];int OperStackTop;double long Number[STACK_SIZE];int NumStackTop;double long NumList[STACK_SIZE];int NumCursor,NumListSize;int OperList[STACK_SIZE];int OperCursor,OperListSize;int WordList[STACK_SIZE];int WordCursor,WordListSize;int Index[MAX+1];int IndexCursor,IndexSize;char Word[WORD_LEN+1];double long num,num1,num2,weight,tempnum;int Oper;int isDecimal,isErr,isNumber,isEnd;char CurrentOper;int i,j,k,m,n;char ch;num=0.0;num2=0.0;tempnum=0.0;Oper=-1;while(1){for(i=0;i<=MAX;i++) //表达式初始化,中间表索引初始化{Expression[i]='\0';Index[i]=-1;}for(i=0;i{Operator[i]='0';Number[i]=0.0;NumList[i]=0.0;OperList[i]=-1;WordList[i]=-1;}NumStackTop=-1; //栈顶指针初始化OperStackTop=0; //操作符栈压⼊\0Operator[OperStackTop]=OperCode('\0');NumCursor=0; //各种中间表指针初始化,各种中间表的长度初始化NumListSize=0;OperCursor=0;OperListSize=0; //操作符表中先写⼊第⼀个操作符'\0'WordCursor=0;WordListSize=0;IndexCursor=0;IndexSize=0;// Index[0]=OPER;printf("Cal>"); //初始化完成,输出提⽰符i=0;while((ch=getchar())!='\n'){if(i>MAX) /*输⼊超长,则出错*/{Err(0,i,"输⼊的表达式长度超过规定值!\n");isErr=1;break;}if(isupper(ch))ch=tolower(ch);Expression[i]=ch;i++;}if(isErr==1){isErr=0;continue;}if(strlen(Expression)==0) //直接回车continue;if(strcmp("end",Expression)==0 ||strcmp("exit",Expression)==0 || strcmp("quit",Expr ession)==0)break;//⼀下代码为编译预处理,主要处理负号,并检查括号是否配对k=0;for(i=0;Expression[i]!='\0';i++){if((i==0&&Expression[i]=='-') || (i>0&&Expression[i]=='-'&&Expression[i-1]=='(')){for(j=strlen(Expression);j>i;j--)Expression[j]=Expression[j-1];Expression[i]='0';}if(Expression[i]=='(') //检查括号k++;if(Expression[i]==')')k--;}if(k>0) //如果括号不配对{Err(1,-1,"缺少右括号 )\n");continue;}if(k<0){Err(1,-1,"缺少左括号 (\n");continue;}//编译预处理结束i=0; //词法分析while(1){if(Expression[i]=='\0'){OperList[OperListSize]=OperCode(Expression[i]);OperListSize++;Index[IndexSize]=OPER;IndexSize++;// printf("IndexSize=%d,Index[IndexSize]=%d,Expression[i]=%c\n",IndexSize,Index[IndexSize],Expression[i]); break;}isDecimal=0;isNumber=0;while(isdigit(Expression[i])||Expression[i]=='.') //读取数字{isNumber=1;if(Expression[i]=='.'){if((i<(MAX-1) && !isdigit(Expression[i+1])) || (i+1)==MAX) //不正确的⼩数点位置{Err(2,i,"⼩数点位置不正确!\n");isErr=1;isNumber=0;i++;break;}isDecimal=1;weight=0.1;i++;continue;}if(isDecimal==0)num=num*10.0+(double long)(Expression[i]-'0');{num=num+(double long)(Expression[i]-'0')*weight;weight=weight*0.1;}i++;} //数字读完if(isErr==1)break;if(isNumber==1) //如果刚才成功读取了数字,则数字⼊栈{NumList[NumListSize]=num;NumListSize++;isNumber=0;num=0.0;Index[IndexSize]=NUM;// printf("IndexSize=%d,Index[IndexSize]=%d\n",IndexSize,Index[IndexSize]); IndexSize++;}for(k=0;k<=WORD_LEN;k++)Word[k]='\0';j=0;while(isalpha(Expression[i])){if(j>=WORD_LEN) //超过长度仍然未匹配,则出错{Err(3,i,"单词长度超过规定值/未定义的单词:");printf("%s\n",Word);isErr=1;break;}Word[j]=Expression[i];j++;// printf("WORD:%s\n",Word);if(WordCode(Word)==-1) //匹配不成功{if(!isalpha(Expression[i+1]))//匹配不成功,但是下⼀个字符已经不是字母,{Err(4,i,"未定义的单词:"); //则出错,并跳出循环printf("%s\n",Word);isErr=1;break;} //匹配不成功且还能继续读取字符,则继续读取下⼀个字母i++;continue;}else //匹配成功,则单词⼊表,读取下⼀个字符{switch(WordCode(Word)){case 0:ch='s';break;case 1:ch='c';break;case 2:case 3:ch='t';break;case 4:ch='C';case 5:ch='l';break;default:ch='\0';WordList[WordListSize]=WordCode(Word);WordListSize++;Index[IndexSize]=WORD;IndexSize++;break;};if(ch!='\0'){OperList[OperListSize]=OperCode(ch);OperListSize++;Index[IndexSize]=OPER;IndexSize++;}i++;break;}} //单词读完if(isErr==1)break;if(Expression[i]==' ')i++;if(!isdigit(Expression[i]) && !isalpha(Expression[i]) && Expression[i]!='\0') {if(OperCode(Expression[i])==-1){isErr=1;Err(5,i,"未定义的操作符:");printf("%c\n",Expression[i]);break;}else{OperList[OperListSize]=OperCode(Expression[i]);OperListSize++;Index[IndexSize]=OPER;IndexSize++;i++;}} //操作符读完if(isErr==1)break;} //词法分析结束if(isErr==1){isErr=0;continue;}/* for(k=0;kprintf("NumList[%d]=%f\n",k,NumList[k]);for(k=0;kprintf("OperList[%d]=%d\n",k,OperList[k]);for(k=0;kprintf("WordList[%d]=%d\n",k,WordList[k]);for(k=0;kprintf("Index[%d]=%d\n",k,Index[k]);printf("\n\n IndexCursor=%d IndexSize=%d,\n",IndexCursor,IndexSize);printf("OperStacktop=%d,Operator[OperStackTop]=%d,NumStackTop=%d\n",OperStackTop,Operator[OperStackTop],NumStackTop); // continue;*/isEnd=0;IndexCursor=0;while(1){if(Index[IndexCursor]==NUM){if(NumCursor<0 || NumListSize<0){Err(10,-1,"索引列表与操作数列表信息不匹配\n");isErr=1;break;}NumStackTop++;Number[NumStackTop]=NumList[NumCursor];NumCursor++;IndexCursor++;continue;} //数字处理if(Index[IndexCursor]==OPER){m=OperList[OperCursor];n=Operator[OperStackTop];switch(Priority[m][n]){case ERR:Err(20,IndexCursor,"不可预见的错误!\n");isErr=1;break;case PUSH:OperStackTop++;Operator[OperStackTop]=m;OperCursor++;IndexCursor++;break;case END:isEnd=1;break;case POP:Oper=Operator[OperStackTop];OperStackTop--;switch(Oper){case BRA_L: IndexCursor++;OperCursor++;break;case ADD:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1+num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(11,IndexCursor,"加法运算缺少操作数!\n");isErr=1;}break;case SUB:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1-num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(12,IndexCursor,"减法运算缺少操作数!\n");isErr=1;}break;case MUL:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1*num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(13,IndexCursor,"乘法运算缺少操作数!\n");isErr=1;}break;case DIV:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;if(num2==0.0){Err(14,IndexCursor,"除数为 0 ,不能进⾏除法运算!\n"); isErr=1;break;}num1=Number[NumStackTop];NumStackTop--;tempnum=num1/num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(15,IndexCursor,"除法运算缺少操作数!\n"); isErr=1;}break;case POW:if(NumStackTop>=1){num2=Number[NumStackTop]; NumStackTop--;num1=Number[NumStackTop]; NumStackTop--;tempnum=pow(num1,num2); NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(16,IndexCursor,"乘⽅运算缺少操作数!\n"); isErr=1;}break;case FAC:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=factorial(num2); NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(17,IndexCursor,"阶乘运算缺少操作数!\n"); isErr=1;}break;case SIN:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=sin(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}{Err(18,IndexCursor,"正弦函数缺少参数!\n"); isErr=1;}break;case COS:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=cos(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(19,IndexCursor,"余弦函数缺少参数!\n"); isErr=1;}break;case TAN:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=tan(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(20,IndexCursor,"正切函数缺少参数!\n");isErr=1;}break;case CTG:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=1.0/tan(num2); NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(21,IndexCursor,"余切函数缺少参数!\n"); isErr=1;}break;/* case LN:if(NumStackTop>=0)num2=Number[NumStackTop]; NumStackTop--;if(num2<=0.0){Err(20,IndexCursor,"⾃然对数函数真数:"); printf(" %f ⼩于0!\n",num2);isErr=1;break;}tempnum=log(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(17,IndexCursor,"⾃然对数函数缺少参数!\n"); isErr=1;}break; */case LG:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;if(num2<=0.0){Err(23,IndexCursor,"常⽤对数函数真数:"); printf(" %f ⼩于0!\n",num2);isErr=1;break;}tempnum=log10(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(22,IndexCursor,"常⽤对数函数缺少参数!\n"); isErr=1;}break;default:Err(100,IndexCursor,"运算符(代码:"); printf(" %d )暂不⽀持!\n",Oper);isErr=1;break;/*#define SIN 9#define COS 10#define TAN 11#define CTG 12#define LOG 13 */}; //switch 语句结束break;};//switchif(isErr==1 || isEnd==1)break;continue;} //运算符处理if(Index[IndexCursor]==WORD){printf(" 单词尚未处理!\n");break;}//在这⾥处理单词}//核⼼计算结束if(isErr==1){isErr=0;continue;}if(NumStackTop>0){Err(1000,-1,"多余的操作数:");printf("%f!\n",Number[NumStackTop]);}elseif(NumStackTop==0 && isEnd==1){if(fabs(Number[NumStackTop])>1e20) printf(" %.20e\n",Number[NumStackTop]); elseprintf(" %f\n",Number[NumStackTop]); isEnd=0;}}//主循环结束}//主函数结束。

JAVA和C#3DES加密解密

JAVA和C#3DES加密解密

JAVA和C#3DES加密解密/// <summary>/// DES3加密解密/// </summary>public class Des3{#region CBC模式**/// <summary>/// DES3 CBC模式加密/// </summary>/// <param name="key">密钥</param>/// <param name="iv">IV</param>/// <param name="data">明文的byte数组</param>/// <returns>密文的byte数组</returns>public static byte[] Des3EncodeCBC( byte[] key, byte[] iv, byte[] data ){//复制于MSDNtry{// Create a MemoryStream.MemoryStream mStream = new MemoryStream();TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();tdsp.Mode = CipherMode.CBC; //默认值tdsp.Padding = PaddingMode.PKCS7; //默认值// Create a CryptoStream using the MemoryStream// and the passed key and initialization vector (IV).CryptoStream cStream = new CryptoStream( mStream,tdsp.CreateEncryptor( key, iv ),CryptoStreamMode.Write );// Write the byte array to the crypto stream and flush it.cStream.Write( data, 0, data.Length );cStream.FlushFinalBlock();// Get an array of bytes from the// MemoryStream that holds the// encrypted data.byte[] ret = mStream.ToArray();// Close the streams.cStream.Close();mStream.Close();// Return the encrypted buffer.return ret;}catch ( CryptographicException e ){Console.WriteLine( "A Cryptographic error occurred: {0}", e.Message );return null;}}/// <summary>/// DES3 CBC模式解密/// </summary>/// <param name="key">密钥</param>/// <param name="iv">IV</param>/// <param name="data">密文的byte数组</param>/// <returns>明文的byte数组</returns>public static byte[] Des3DecodeCBC( byte[] key, byte[] iv,byte[] data ){try{// Create a new MemoryStream using the passed// array of encrypted data.MemoryStream msDecrypt = new MemoryStream( data );TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();tdsp.Mode = CipherMode.CBC;tdsp.Padding = PaddingMode.PKCS7;// Create a CryptoStream using the MemoryStream// and the passed key and initialization vector (IV).CryptoStream csDecrypt = new CryptoStream( msDecrypt, tdsp.CreateDecryptor( key, iv ),CryptoStreamMode.Read );// Create buffer to hold the decrypted data.byte[] fromEncrypt = new byte[data.Length];// Read the decrypted data out of the crypto stream// and place it into the temporary buffer.csDecrypt.Read( fromEncrypt, 0, fromEncrypt.Length );//Convert the buffer into a string and return it.return fromEncrypt;}catch ( CryptographicException e ){Console.WriteLine( "A Cryptographic error occurred: {0}", e.Message );return null;}}#endregion#region ECB模式/// <summary>/// DES3 ECB模式加密/// </summary>/// <param name="key">密钥</param>/// <param name="iv">IV(当模式为ECB时,IV无用)</param>/// <param name="str">明文的byte数组</param>/// <returns>密文的byte数组</returns>public static byte[] Des3EncodeECB( byte[] key, byte[] iv, byte[] data ){try{// Create a MemoryStream.MemoryStream mStream = new MemoryStream();TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();tdsp.Mode = CipherMode.ECB;tdsp.Padding = PaddingMode.PKCS7;// Create a CryptoStream using the MemoryStream// and the passed key and initialization vector (IV).CryptoStream cStream = new CryptoStream( mStream,tdsp.CreateEncryptor( key, iv ),CryptoStreamMode.Write );// Write the byte array to the crypto stream and flush it.cStream.Write( data, 0, data.Length );cStream.FlushFinalBlock();// Get an array of bytes from the// MemoryStream that holds the// encrypted data.byte[] ret = mStream.ToArray();// Close the streams.cStream.Close();mStream.Close();// Return the encrypted buffer.return ret;}catch ( CryptographicException e ){Console.WriteLine( "A Cryptographic error occurred: {0}", e.Message );return null;}}/// <summary>/// DES3 ECB模式解密/// </summary>/// <param name="key">密钥</param>/// <param name="iv">IV(当模式为ECB时,IV无用)</param>/// <param name="str">密文的byte数组</param>/// <returns>明文的byte数组</returns>public static byte[] Des3DecodeECB( byte[] key, byte[] iv, byte[] data ){try{// Create a new MemoryStream using the passed// array of encrypted data.MemoryStream msDecrypt = new MemoryStream( data );TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();tdsp.Mode = CipherMode.ECB;tdsp.Padding = PaddingMode.PKCS7;// Create a CryptoStream using the MemoryStream// and the passed key and initialization vector (IV).CryptoStream csDecrypt = new CryptoStream( msDecrypt, tdsp.CreateDecryptor( key, iv ),CryptoStreamMode.Read );// Create buffer to hold the decrypted data.byte[] fromEncrypt = new byte[data.Length];// Read the decrypted data out of the crypto stream// and place it into the temporary buffer.csDecrypt.Read( fromEncrypt, 0, fromEncrypt.Length );//Convert the buffer into a string and return it.return fromEncrypt;}catch ( CryptographicException e ){Console.WriteLine( "A Cryptographic error occurred: {0}", e.Message );return null;}}#endregion/// <summary>/// 类<a href="/base/softwaretest"class='replace_word' title="软件测试知识库" target='_blank' style='color:#df3434; font-weight:bold;'>测试</a>/// </summary>public static void T est(){System.Text.Encoding utf8 = System.T ext.Encoding.UTF8;//key为abcdefghijklmnopqrstuvwx的Base64编码byte[] key = Convert.FromBase64String( "YWJjZGVmZ2hpamtsbW5vcHFyc3R 1dnd4" );byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; //当模式为ECB 时,IV无用byte[] data = utf8.GetBytes( "中国ABCabc123" );System.Console.WriteLine( "ECB模式:" );byte[] str1 = Des3.Des3EncodeECB( key, iv, data );byte[] str2 = Des3.Des3DecodeECB( key, iv, str1 );System.Console.WriteLine( Convert.T oBase64String( str1 ) );System.Console.WriteLine( System.Text.Encoding.UTF8.GetSt ring( str2 ) );System.Console.WriteLine();System.Console.WriteLine( "CBC模式:" );byte[] str3 = Des3.Des3EncodeCBC( key, iv, data );byte[] str4 = Des3.Des3DecodeCBC( key, iv, str3 );System.Console.WriteLine( Convert.T oBase64String( str3 ) );System.Console.WriteLine( utf8.GetString( str4 ) );System.Console.WriteLine();}}。

CSDN技术中心一个从网上搜到的3DES加解密C++代码

CSDN技术中心一个从网上搜到的3DES加解密C++代码

CSDN技术中心一个从网上搜到的3DES加解密C++代码一个从网上搜到的3DES加解密C++代码选择自JasonHeung 的 Blog一个从网上搜到的3DES加解密C++代码#if !defined(_CRYPT3DES_H)#define _CRYPT3DES_H#if !defined(ED_FLAG)#define ED_FLAG#define encrypt 0#define decrypt 1#endif#ifndef _WINDOWS_#include "windows.h"#endif/////////////////////////////////////////////////////////////////// ////////*unsigned char key[8] = {"doks"};unsigned char buff[8] = {"abcdef"};C3DES des;des.DoDES3(0,buff,key);des.DoDES3(1,buff,key);*//* 3DES Class. */class C3DES{public:BOOL DoDES3(int nWay,unsigned char* pSrc,int nSrcSize,unsigned char* pDes,unsigned char pKey[8]);private:BOOL DoDES3(unsigned char EDFlag, //EDFlag是加\脱密标志,0表示加密,1表示脱密unsigned char databuf[8], //DataBuf将被处理的明文或密文的缓冲区,并兼作输出缓冲区unsigned char keybuf[8] //8byte的密钥缓冲区);inline void pro_key(void);inline void first_p(void);inline void expand_x(void);inline void fction(void);inline void make(BOOL FirstFlag);static const unsigned long sp0[64],sp1[64],sp2[64],sp3[64],sp4[64],sp5[64],sp6[64],sp7[64];static const unsigned char pc0[64],pc0_v[64],pc1[56],pc2[48],rotate[16],bytebit[8];static const unsigned long bigbyte[24],bigbyte1[32];unsigned char key[8],m[8],c[8],k[16][8],s_in[8],pc[64];unsigned char ed_flag;unsigned long x[2];};#endif#include "stdafx.h"#include "3DES.h"const unsigned long C3DES::sp0[64]={0x00808200,0x00000000,0x00008000,0x00808 202,0x00808002,0x00008202,0x00000002,0x00008000,0x00000200,0x00808200,0x00808202,0x00000200,0x00800202,0x00808002,0x00800000,0x00000002,0x00000202,0x00800200,0x00800200,0x00008200,0x00008200,0x00808000,0x00808000,0x00800202,0x00008002,0x00800002,0x00800002,0x00008002,0x00000000,0x00000202,0x00008202,0x00800000,0x00008000,0x00808202,0x00000002,0x00808000,0x00808200,0x00800000,0x00800000,0x00000200,0x00808002,0x00008000,0x00008200,0x00800002,0x00000200,0x00000002,0x00800202,0x00008202,0x00808202,0x00008002,0x00808000,0x00800202,0x00800002,0x00000202,0x00008202,0x00808200,0x00000202,0x00800200,0x00800200,0x00000000,0x00008002,0x00008200,0x00000000,0x00808002},C3DES::sp1[64]={0x40084010,0x40004000,0x00004000,0x00 084010,0x00080000,0x00000010,0x40080010,0x40004010,0x40000010,0x40084010,0x40084000,0x40000000,0x40004000,0x00080000,0x00000010,0x40080010,0x00084000,0x00080010,0x40004010,0x00000000,0x40000000,0x00004000,0x00084010,0x40080000,0x00080010,0x40000010,0x00000000,0x00084000,0x4010,0x40084000,0x40080000,0x4010,0x0,0x84010,0x40080010,0x80000,0x40004010,0x40080000,0x40084000,0x4000,0x40080000,0x40004000,0x10,0x40084010,0x84010,0x10,0x4000,0x40000000,0x4010,0x40084000,0x80000,0x40000010,0x80010,0x40004010,0x40000010,0x80010,0x84000,0x0,0x40004000,0x4010,0x40000000,0x40080010,0x40084010,0x84000},C3DES::sp2[64]={0x104,0x4010100,0x0,0x4010004,0x4000100,0x0,0x10104,0x4000100,0x10004,0x4000004,0x4000004,0x10000,0x4010104,0x10004,0x4010000,0x104,0x4000000,0x4,0x4010100,0x100,0x10100,0x4010000,0x4010004,0x10104,0x4000104,0x10100,0x10000,0x4000104,0x4,0x4010104,0x100,0x4000000,0x4010100,0x4000000,0x10004,0x104,0x10000,0x4010100,0x4000100,0x0,0x100,0x10004,0x4010104,0x4000100,0x4000004,0x100,0x0,0x4010004,0x4000104,0x10000,0x4000000,0x4010104,0x4,0x10104,0x10100,0x4000004,0x4010000,0x4000104,0x104,0x4010000,0x10104,0x4,0x4010004,0x10100},C3DES::sp3[64]={0x80401000,0x80001040,0x80001040,0x40, 0x401040,0x80400040,0x80400000,0x80001000,0x0,0x401000,0x401000,0x80401040,0x80000040,0x0,0x400040,0x80400000,0x80000000,0x1000,0x400000,0x80401000,0x40,0x400000,0x80001000,0x1040,0x80400040,0x80000000,0x1040,0x400040,0x1000,0x401040,0x80401040,0x80000040,0x400040,0x80400000,0x401000,0x80401040,0x80000040,0x0,0x0,0x401000,0x1040,0x400040,0x80400040,0x80000000,0x80401000,0x80001040,0x80001040,0x40,0x80401040,0x80000040,0x80000000,0x1000,0x80400000,0x80001000,0x401040,0x80400040,0x80001000,0x1040,0x400000,0x80401000,0x40,0x400000,0x1000,0x401040},C3DES::sp4[64]={0x80,0x1040080,0x1040000,0x21000080, 0x40000,0x80,0x20000000,0x1040000,0x20040080,0x40000,0x1000080,0x20040080,0x21000080,0x21040000,0x40080,0x20000000,0x1000000,0x20040000,0x20040000,0x0,0x20000080,0x21040080,0x21040080,0x1000080,0x21040000,0x20000080,0x0,0x21000000,0x1040080,0x1000000,0x21000000,0x40080,0x40000,0x21000080,0x80,0x1000000,0x20000000,0x1040000,0x21000080,0x20040080,0x1000080,0x20000000,0x21040000,0x1040080,0x20040080,0x80,0x1000000,0x21040000,0x21040080,0x40080,0x21000000,0x21040080,0x1040000,0x0,0x20040000,0x21000000,0x40080,0x1000080,0x20000080,0x40000,0x0,0x20040000,0x1040080,0x20000080},C3DES::sp5[64]={0x10000008,0x10200000,0x2000,0x102020 08,0x10200000,0x8,0x10202008,0x200000,0x10002000,0x202008,0x200000,0x10000008,0x200008,0x10002000,0x10000000,0x2008,0x0,0x200008,0x10002008,0x2000,0x202000,0x10002008,0x8,0x10200008,0x10200008,0x0,0x202008,0x10202000,0x2008,0x202000,0x10202000,0x10000000,0x10002000,0x8,0x10200008,0x202000,0x10202008,0x200000,0x2008,0x10000008,0x200000,0x10002000,0x10000000,0x2008,0x10000008,0x10202008,0x202000,0x10200000,0x202008,0x10202000,0x0,0x10200008,0x8,0x2000,0x10200000,0x202008,0x2000,0x200008,0x10002008,0x0,0x10202000,0x10000000,0x200008,0x10002008},C3DES::sp6[64]={0x100000,0x2100001,0x2000401,0x0, 0x400,0x2000401,0x100401,0x2100400,0x2100401,0x100000,0x0,0x2000001,0x1,0x2000000,0x2100001,0x401,0x2000400,0x100401,0x100001,0x2000400,0x2000001,0x2100000,0x2100400,0x100001,0x2100000,0x400,0x401,0x2100401,0x100400,0x1,0x2000000,0x100400,0x2000000,0x100400,0x100000,0x2000401,0x2000401,0x2100001,0x2100001,0x1,0x100001,0x2000000,0x2000400,0x100000,0x2100400,0x401,0x100401,0x2100400,0x401,0x2000001,0x2100401,0x2100000,0x100400,0x0,0x1,0x2100401,0x0,0x100401,0x2100000,0x400,0x2000001,0x2000400,0x400,0x100001},C3DES::sp7[64]={0x8000820,0x800,0x20000,0x8020820, 0x8000000,0x8000820,0x20,0x8000000,0x20020,0x8020000,0x8020820,0x20800,0x8020800,0x20820,0x800,0x20,0x8020000,0x8000020,0x8000800,0x820,0x20800,0x20020,0x8020020,0x8020800,0x820,0x0,0x0,0x8020020,0x8000020,0x8000800,0x20820,0x20000,0x20820,0x20000,0x8020800,0x800,0x20,0x8020020,0x800,0x20820,0x8000800,0x20,0x8000020,0x8020000,0x8020020,0x8000000,0x20000,0x8000820,0x0,0x8020820,0x20020,0x8000020,0x8020000,0x8000800,0x8000820,0x0,0x8020820,0x20800,0x20800,0x820,0x820,0x20020,0x8000000,0x8020800};const unsigned char C3DES::pc0[64]={57,49,41,33,25,17, 9, 1,59,51,43,35,27,19,11, 3,61,53,45,37,29,21,13, 5,63,55,47,39,31,23,15, 7,56,48,40,32,24,16, 8, 0,58,50,42,34,26,18,10, 2,60,52,44,36,28,20,12, 4,62,54,46,38,30,22,14, 6},C3DES::pc0_v[64]={39, 7,47,15,55,23,63,31,38, 6,46,14,54,22,62,30,37, 5,45,13,53,21,61,29,36, 4,44,12,52,20,60,28,35, 3,43,11,51,19,59,27,34, 2,42,10,50,18,58,26,33, 1,41, 9,49,17,57,25,32, 0,40, 8,48,16,56,24};const unsigned char C3DES::pc1[56]={56,48,40,32,24,16, 8, 0,57,49,41,33,25,17,9, 1,58,50,42,34,26,18,10, 2,59,51,43,35,62,54,46,38,30,22,14, 6,61,53,45,37,29,21,13, 5,60,52,44,36,28,20,12, 4,27,19,11, 3},C3DES::pc2[48]={13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31},C3DES::rotate[16]={1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,2 8};const unsigned char C3DES::bytebit[8]={0200,0100,040,020,010,04,02,01};//八进制数据const unsigned long C3DES::bigbyte[24]={0x800000,0x400000,0x200000,0x100000, 0x80000, 0x40000, 0x20000, 0x10000,0x8000, 0x4000, 0x2000, 0x1000,0x800, 0x400, 0x200, 0x100,0x80, 0x40, 0x20, 0x10,0x8, 0x4, 0x2, 0x1},C3DES::bigbyte1[32]={0x80000000,0x40000000,0x20000000 ,0x10000000,0x8000000, 0x4000000, 0x2000000, 0x1000000,0x800000, 0x400000, 0x200000, 0x100000,0x80000, 0x40000, 0x20000, 0x10000,0x8000, 0x4000, 0x2000, 0x1000,0x800, 0x400, 0x200, 0x100,0x80, 0x40, 0x20, 0x10,0x8, 0x4, 0x2, 0x1};void C3DES::make(BOOL FirstFlag)//操作过程:根据事先预置在key[8],m[8],ed_flag中的数据进行//加密\脱密操作,将结果保存在c[8]中。

c语言密码生成

c语言密码生成

计算机实习报告一题目分析1 实验题目:实现一个简单的密码生成系统。

一个有效的密码由L(3<=L<=15)个小写字母(来自传统的拉丁字母集'a'...'z')组成,至少有一个元音字母('a','e','i','o'或者'u'),至少有两个辅音字母(除去元音以外的字母),并且按字母表顺序出现(例如,'acd'是有效的,而'dac'不是)。

给定一个期望长度L和若干个小写字母,写一个程序,打印出所有的长度为L、能由这些字母组成的有效密码。

密码必须按字母表顺序打印出来。

2 题目分析本次计算机实习的任务实现一个密码生成系统,也就是在输入的一串字符中,找出L个(L是给定的长度)组成一组,而且要满足如下要求:(1)每组中至少有一个元音字符,和至少两个辅音字符;(2)按字母表顺序出现;(3)打印出所有的长度为L、能由这些字母组成的有效密码。

关键部分是(3),在输入的一串字符中找出所有由L个字符组成的密码,不能有遗漏。

这可以用循环实现。

其次是(2),这相当于数组排列。

然后用循环逐个判断每一组中的L个字符,检查是否符合要求(1)。

二程序设计1 设计思想(1)首先从键盘输入用来生成密码的字符,保存在字符数组chars[]中;(2)测试chars[]的长度N,对给定的密码长度L(N>=L);(3) 编写一个子函数sort( ),实现将其中的字符按字母表顺序排列;(4) 用多重循环,取出由chars[]中的字符组成的所有长为L的字符串,存到str_out[]中;(5) 编写子函数wyp( ),判断str_out[]是否满足含有至少一个元音字符和至少两个辅音字符,满足返回值为0,否则返回值为1;(6) 如果str_out[]满足要求,打印出来,利用循环,直到找出所有满足要求的生成密码str_out[]。

c++三位数运算程序

c++三位数运算程序
}
这个程序首先要求用户输入两个三位数和一个运算符,然后根据运算符执行相应的运算,并输出结果。如果用户输入的运算符不是加、减、乘、除中的一个,程序将输出一个错误消息。如果用户尝试除以零,程序也将输出一个错误消息。
cin >> num1;
cout << "请输入运算符 (+, -, *, /): ";
cin >> op;
cout << "请输入第二个三位数: ";
cin >> num2;
switch (op) {
case '+':
result = num1 + num2;
cout << "结果是: " << result << endl;
break;
case '-':
result = num1 - num2;
cout << "结果是: " << result << endl;
break;
case '*':
result = num1 * num2;
cout << "结果是: " << result << endl;
break;
case '/':
if (num2 == 0) {
cout &t;< endl;
break;
}
result = num1 / num2;
cout << "结果是: " << result << endl;
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include<stdio.h>
#include<windows.h>//cls清屏功能函数调用
int main()
{
FILE *fp;
int i,j,k,l,m,o,p,q,r,s,t,u,v,w,x,y,n;
char d;
char *a="00123456789abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU VWXYZ[]~.',/\\:!?@#$%^&*()<>_+|~`{ }-;\"";
printf("★**************************************************************★\n");
printf("§*******************★欢迎使用密码破解程序系统★*****************§\n");
printf("§************************************************** ************§\n");
printf("§§
§§\n");
printf("§§
§§\n");
printf("§§
§§\n");
printf("§§☆1 . 启动生成1位密码程序 §§\n");
printf("§§☆2 . 启动生成2位密码程序§§\n");
printf("§§☆ 3 . 启动生成3位密码程序§§\n");
printf("§§
§§\n");
printf("§§
§§\n");
printf("★**************************************************************★\n");
printf("◆请选择要破译密码的长度(0-6)后按下回车键启动破解程序:\n");
scanf("%d",&n);
system("cls");
switch(n)
{
case 1:
{
fp=fopen("1位密码字典.txt","w+");
for(i=1;i<=97;i++)
{
fprintf(fp,"%c\t",a);
}
printf("\n");
break;
}
case 2:
{
fp=fopen("2位密码字典.txt","w+");
for(i=1;i<=97;i++)
{
{
for(j=1;j<=97;j++)
fprintf(fp,"%c%c\t",a,a[j]);
}
}
printf("\n");
break;
}
case 3:
{
fp=fopen("3位密码字典.txt","w+");
for(i=1;i<=97;i++)
{
{
for(j=1;j<=97;j++)
for(k=1;k<=97;k++)
fprintf(fp,"%c%c%c\t",a,a[j],a[k ]);
}
}
printf("\n");
break;
}
default : printf("enter data error!\n");
}
fclose(fp);
printf("%d位密码字典已经生成!\n",n);
return 0;
}
************************************************************** ************************************************************** *************************************************。

相关文档
最新文档