#include <stringh>
struct e
{
char a[10];
char b[10];
}z;
int main()
{ int t=0;
char s[10],d[10];
FILE p;
void as();
if ((p=fopen("mtxt","r+"))==NULL)
{
p=fopen("mtxt","w+");
t=1;
}
if(t==1)
{
printf("当前没有任何用户\n");
printf("请新建用户名: ");
scanf("%s",s);
printf("为用户设置密码: ");
scanf("%s",d);
strcpy(za,s);
strcpy(zb,d);
fprintf(p,"%s %s",za,zb);
fclose(p);
}
if(t==0)
{
printf("请输入用户名: ");
scanf("%s",s);
fscanf(p,"%s %s",za,zb);
fclose(p);
if (!strcmp(za,s))
{
printf("请输入密码:");
scanf("%s",d);getchar();
if(!strcmp(zb,d))
{ char i;
printf("是否要修改密码?(输入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("请输入修改密码:");
scanf("%s",zb);
p=fopen("mtxt","w+");
fprintf(p,"%s %s",za,zb);
fclose(p);
printf("修改成功!");
}
}
else printf("密码错误!");
}
else printf("用户名错误");
fclose(p);
}
}
#include <stdioh>
#include <stringh>
#include "globalh"
#include "md5h"
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char
[64]));
static void Encode PROTO_LIST
((unsigned char , UINT4 , unsigned int));
static void Decode PROTO_LIST
((UINT4 , unsigned char , unsigned int));
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned
int));
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
#define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b);}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
void MD5Init (context)
MD5_CTX context;
{
context->count[0] = context->count[1] = 0;
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
}
void MD5Update (context, input, inputLen)
MD5_CTX context;
unsigned char input;
unsigned int inputLen;
{
unsigned int i, index, partLen;
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
if ((context->count[0] += ((UINT4)inputLen << 3))< ((UINT4)inputLen << 3))
context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29);
partLen = 64 - index;
if (inputLen >= partLen)
{
MD5_memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform (context->state, &input[i]);
index = 0;
}
else
i = 0;
MD5_memcpy((POINTER)&context->buffer[index], (POINTER)&input[i],inputLen-i);
}
void MD5Final (digest, context)
unsigned char digest[16];
MD5_CTX context;
{
unsigned char bits[8];
unsigned int index, padLen;
Encode (bits, context->count, 8);
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) (56 - index) : (120 - index);
MD5Update (context, PADDING, padLen);
MD5Update (context, bits, 8);
Encode (digest, context->state, 16);
MD5_memset ((POINTER)context, 0, sizeof (context));
}
static void MD5Transform (UINT4 state[4], unsigned char block[64])
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
Decode (x, block, 64);
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); / 1 /
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); / 2 /
FF (c, d, a, b, x[ 2], S13, 0x242070db); / 3 /
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); / 4 /
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); / 5 /
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); / 6 /
FF (c, d, a, b, x[ 6], S13, 0xa8304613); / 7 /
FF (b, c, d, a, x[ 7], S14, 0xfd469501); / 8 /
FF (a, b, c, d, x[ 8], S11, 0x698098d8); / 9 /
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); / 10 /
FF (c, d, a, b, x[10], S13, 0xffff5bb1); / 11 /
FF (b, c, d, a, x[11], S14, 0x895cd7be); / 12 /
FF (a, b, c, d, x[12], S11, 0x6b901122); / 13 /
FF (d, a, b, c, x[13], S12, 0xfd987193); / 14 /
FF (c, d, a, b, x[14], S13, 0xa679438e); / 15 /
FF (b, c, d, a, x[15], S14, 0x49b40821); / 16 /
/ Round 2 /
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); / 17 /
GG (d, a, b, c, x[ 6], S22, 0xc040b340); / 18 /
GG (c, d, a, b, x[11], S23, 0x265e5a51); / 19 /
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); / 20 /
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); / 21 /
GG (d, a, b, c, x[10], S22, 0x2441453); / 22 /
GG (c, d, a, b, x[15], S23, 0xd8a1e681); / 23 /
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); / 24 /
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); / 25 /
GG (d, a, b, c, x[14], S22, 0xc33707d6); / 26 /
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); / 27 /
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); / 28 /
GG (a, b, c, d, x[13], S21, 0xa9e3e905); / 29 /
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); / 30 /
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); / 31 /
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); / 32 /
/ Round 3 /
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); / 33 /
HH (d, a, b, c, x[ 8], S32, 0x8771f681); / 34 /
HH (c, d, a, b, x[11], S33, 0x6d9d6122); / 35 /
HH (b, c, d, a, x[14], S34, 0xfde5380c); / 36 /
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); / 37 /
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); / 38 /
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); / 39 /
HH (b, c, d, a, x[10], S34, 0xbebfbc70); / 40 /
HH (a, b, c, d, x[13], S31, 0x289b7ec6); / 41 /
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); / 42 /
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); / 43 /
HH (b, c, d, a, x[ 6], S34, 0x4881d05); / 44 /
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); / 45 /
HH (d, a, b, c, x[12], S32, 0xe6db99e5); / 46 /
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); / 47 /
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); / 48 /
/ Round 4 /
II (a, b, c, d, x[ 0], S41, 0xf4292244); / 49 /
II (d, a, b, c, x[ 7], S42, 0x432aff97); / 50 /
II (c, d, a, b, x[14], S43, 0xab9423a7); / 51 /
II (b, c, d, a, x[ 5], S44, 0xfc93a039); / 52 /
II (a, b, c, d, x[12], S41, 0x655b59c3); / 53 /
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); / 54 /
II (c, d, a, b, x[10], S43, 0xffeff47d); / 55 /
II (b, c, d, a, x[ 1], S44, 0x85845dd1); / 56 /
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); / 57 /
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); / 58 /
II (c, d, a, b, x[ 6], S43, 0xa3014314); / 59 /
II (b, c, d, a, x[13], S44, 0x4e0811a1); / 60 /
II (a, b, c, d, x[ 4], S41, 0xf7537e82); / 61 /
II (d, a, b, c, x[11], S42, 0xbd3af235); / 62 /
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); / 63 /
II (b, c, d, a, x[ 9], S44, 0xeb86d391); / 64 /
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
MD5_memset ((POINTER)x, 0, sizeof (x));
}
static void Encode (output, input, len)
unsigned char output;
UINT4 input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
{
output[j] = (unsigned char)(input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
}
}
static void Decode (output, input, len)
UINT4 output;
unsigned char input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
static void MD5_memcpy (output, input, len)
POINTER output;
POINTER input;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
output[i] = input[i];
}
static void MD5_memset (output, value, len)
POINTER output;
int value;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
((char )output)[i] = (char)value;
}
#ifndef MD
#define MD 5
#endif
#define TEST_BLOCK_LEN 1000
#define TEST_BLOCK_COUNT 1000
static void MDString PROTO_LIST ((char ));
static void MDPrint PROTO_LIST ((unsigned char [16]));
#define MD_CTX MD5_CTX
#define MDInit MD5Init
#define MDUpdate MD5Update
#define MDFinal MD5Final
int main (int argc, char argv[])
{
int i;
if (argc > 1)
{ MDString(argv[1]);
return (0);
}
}
static void MDString (char string)
{
MD_CTX context;
unsigned char digest[16];
unsigned int len = strlen (string);
MDInit (&context);
MDUpdate (&context, string, len);
MDFinal (digest, &context);
printf ("MD%d (\"%s\") = ", MD, string);
MDPrint (digest);
printf ("\n");
}
static void MDPrint (unsigned char digest[16])
{
unsigned int i;
for (i = 0; i < 16; i++)
printf ("%02x", digest[i]);
}
// 希尔算法的加密与解密
#include <stdioh>
#include <stringh>
#include <conioh>
#include <ctypeh>
#include <memoryh>// nDime为全部变量,可逆矩阵的维数
int nDime;
int index = 0;// MAXN为明文的最大长度
const int MAXN = 256;// 矩阵相乘,a是一个列为1的矩阵
void MultiplyMatrix(int a[], int b[][10], int text)
{
int i, j, t; for (i = 0; i < nDime; i++)
{
t = 0;
for (j = 0;j < nDime; j++)
t += b[i][j] a[j];
text[index++] = t;
}
}// 求行列式的值
int determinant(int m[][10], int size)
{
int row, column;
int temp1[10], temp2[10], t; for (column = 0; column < size; column++)
{
temp1[column] = m[0][column];
temp2[column] = m[0][column];
}
for (row = 1; row < size; row++)
{
for (column = 0; column < size; column++)
{
int diff = column - row;
int sum = column + row;
if (diff < 0)
diff += size;
if (sum >= size)
sum %= size;
temp1[diff] = m[row][column];
temp2[sum] = m[row][column];
}
}
t = 0;
for (row = 0; row < size; row++)
t += temp1[row] - temp2[row]; return t;
}// 求矩阵中某一元素的代数余子式
int func(int matrix[][10], const int i, const int j)
{
int row, column, m, n;
int NewMatrix[10][10]; m = n = 0;
for (row = 0; row < nDime; row++)
{
if (i == row)
continue;
for (column = 0; column < nDime; column++)
{
if (j == column)
continue;
NewMatrix[m++][n++] = matrix[row][column];
}
}
printf ("New Array:\n");
for (row = 0; row < nDime - 1; row++)
{
for (column = 0; column < nDime - 1; column++)
printf("%d ", NewMatrix[row][column]);
printf("\n");
} int sign = (!((i + j) % 2)) 1 : -1;
return sign determinant(NewMatrix, nDime - 1);
}// 对矩阵求逆,cm矩阵与m矩阵互逆
void ConverseMatrix(int m[][10], int cm[][10])
{
// 矩阵求逆,利用数学公式A(逆)= (1 / |A|)乘以A
// 其中,|A|表示行列式A的值,而A表示矩阵A的伴随矩阵
int row, column;
int StarMat[10][10]; // StarMat表示m的伴随矩阵
int t; // 初始化伴随矩阵
for (row = 0; row < 10; row++)
for (column = 0; column < 10; column++)
StarMat[row][column] = 0; // 求伴随矩阵
for (row = 0; row < nDime; row++)
for (column = 0; column < nDime; column++)
{
StarMat[row][column] = func(m, row, column);
printf("伴随矩阵:%d", StarMat[row][column]);
} // 求行列式的值
t = determinant(m, nDime); // 求出逆向矩阵
for (row = 0; row < nDime; row++)
for (column = 0; column < nDime; column++)
cm[row][column] = StarMat[row][column] / t;
// 输出逆向矩阵
for (row = 0; row < nDime; row++)
for (column = 0; column < nDime; column++)
printf("%d ", cm[row][column]);
printf("\n");
}// 希尔加密及解密算法
void ShellPassword(int OText, int TextLen, int matrix[][10], int text)
{
int i, j, n, a[10];
// 判断要将OText分成几部分
n = TextLen / nDime;
if (TextLen % nDime)
n++; // 矩阵相乘
// 将OText分成的几部分分别与matrix矩阵相乘
for (i = 0; i < n; i++)
{
for (j = 0; j < 10; j++)
a[j] = 0;
for (j = 0; j < nDime; j++)
a[j] = OText[i nDime + j];
MultiplyMatrix(a, matrix, text);
}
}
int main(void)
{
int i, temp, row, column;
// matrix存放加密或解密矩阵,Password为加密后的结果
// OText存放原文转换为普通数字,如A~1,Z~26
int matrix[10][10], ConMatrix[10][10], OText[MAXN], Password[MAXN], OriText[MAXN];
char text[MAXN];
char sel; printf("=================================================\n");
putchar('\n');
printf(" SHELL加密解密器\n");
putchar('\n');
printf("=================================================\n"); while (1)
{
// 初始化矩阵
for (row = 0; row < 10; row++)
for (column = 0; column < 10; column++)
matrix[row][column] = 0; putchar('\n');
printf("1加密\n");
printf("2解密\n");
printf("0退出\n");
printf("请输入你的选择:\n");
sel = getche(); switch (sel)
{
case '1':
printf("\n请输入原文:\n");
memset(text, '\0', sizeof(text) / sizeof(char));
memset(Password, 0, sizeof(Password) / sizeof(int));
gets(text); printf("输入加密矩阵的维数,维数不能超过10维:\n");
scanf("%d", &nDime);
printf("输入矩阵,该矩阵必须为可逆矩阵,否则将不能进行解密:\n");
// 可逆矩阵即,设A为n阶矩阵,如果存n在阶矩阵B使得AB=BA=1
// 则矩阵A是可逆的,称B是A的逆矩阵
for (row = 0; row < nDime; row++)
for (column = 0; column < nDime; column++)
scanf("%d", &matrix[row][column]);
// 将小写字母转换为大写字母
for (i = 0; text[i] != '\0'; i++)
if (islower(text[i]))
text[i] |= 0x20;
// OText存放将字母转换为相应数,如A~1,Z~26
for (i = 0; i < MAXN; i++)
OText[i] = 0;
for (i = 0; text[i] != '\0'; i++)
OText[i] = text[i] - 'A' + 1;
// 加密
ShellPassword(OText, strlen(text), matrix, Password);
// 将加密后的内容打印出来
printf("加密后的内容为:\n");
for (i = 0; i < strlen(text); i++)
printf("%d ", Password[i]);
putchar('\n');
break;
case '2':
break;
case '0':
return 0;
default:
break;
}
getchar();
} return 0;
} 译码算法我会在明天上传上来,你的加密密钥是一个三阶的数组,密文C是:1729 2514 811 1659 2472 858 1739 2514 849 1902 2736 905 1659 2472 858
conioh不是c标准头文件,建议不要用这个头文件。把这个头文件删掉。
将读入密码那行的函数改用gets
gets(input_pass);
另外为了避免bug,input_pass最好弄大一点。
C语言特点
基本特性
C++语言代码
1、高级语言:它是把高级语言的基本结构和语句与低级语言的实用性结合起来的工作单元。 [10]
2、结构式语言:结构式语言的显著特点是代码及数据的分隔化,即程序的各个部分除了必要的信息交流外彼此独立。这种结构化方式可使程序层次清晰,便于使用、维护以及调试。C 语言是以函数形式提供给用户的,这些函数可方便的调用,并具有多种循环、条件语句控制程序流向,从而使程序完全结构化。 [10]
4、代码级别的跨平台:由于标准的存在,使得几乎同样的C代码可用于多种 *** 作系统,如Windows、DOS、UNIX等等;也适用于多种机型。C语言对编写需要进行硬件 *** 作的场合,优于其它高级语言。 [10]
5、使用指针:可以直接进行靠近硬件的 *** 作,但是C的指针 *** 作不做保护,也给它带来了很多不安全的因素。C++在这方面做了改进,在保留了指针 *** 作的同时又增强了安全性,受到了一些用户的支持,但是,由于这些改进增加语言的复杂度,也为另一部分所诟病。Java则吸取了C++的教训,取消了指针 *** 作,也取消了C++改进中一些备受争议的地方,在安全性和适合性方面均取得良好的效果,但其本身解释在虚拟机中运行,运行效率低于C++/C。一般而言,C,C++,java被视为同一系的语言,它们长期占据着程序使用榜的前三名。 [11]
特有特点
C语言是一个有结构化程序设计、具有变量作用域(variable scope)以及递归功能的过程式语言。
C语言传递参数均是以值传递(pass by value),另外也可以传递指针(a pointer passed by value)。
不同的变量类型可以用结构体(struct)组合在一起。
只有32个保留字(reserved keywords),使变量、函数命名有更多d性。
部份的变量类型可以转换,例如整型和字符型变量。
通过指针(pointer),C语言可以容易的对存储器进行低级控制。
预编译处理(preprocessor)让C语言的编译更具有d性。
#include <stdioh>
#include <conioh>
#include <stringh>
#include <dosh>
void main()
{
int i=0,j;
char str1[10],str2[10]="123456";;
while(1)
{
printf("\n请输入6位密码,按Enter键结束: ");
j=0;
while ((str1[j]=getch()))
{
printf("%c", '');
j++;
if(j==6) break;
}
str1[j]=0;
if(j>0 && strcmp(str1,str2)==0)
{
printf("\n密码正确!\n");
break;
}
else if(i<2) printf("\n输入有错误,还有 %d 次机会\n",2-i);
i++;
if(i>=3)
{
i=0;
sleep(180);
}
}
}
花了些时间写的,希望对你有帮助~
#include<stdioh>
#define N 3 //可加密的字符串长度
char plaintext[N]=; //明文,输入时输入字符,参与运算时强制转换成整数
int ciphertext[N]=; //密文,保存成整数,输出时强制转换成字符
int key[N][N]; //密钥矩阵
void getPlainText() //获得明文字符串
{
printf("请输入明文:");
scanf("%s",plaintext);
printf("\n");
}
void getKey() //输入密钥矩阵
{
int i,j;
printf("请输入加密矩阵:\n");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
scanf("%d",&key[i][j]);
printf("\n");
}
void hill() //Hill加密算法
{
int i,j;
for(i=0;i<N;i++){ //矩阵的乘法
for(j=0;j<N;j++){ //计算转换依据,0~25对应a~z
ciphertext[i]+=key[i][j](int)(plaintext[j]-'a');
ciphertext[i]%=26;
}
}
printf("\n");
}
void printCipherText() //输出加密后的密文
{
int i;
printf("加密后的密文是:");
for(i=0;i<N;i++) //把参与计算后是整数强制转换成对应的字符
printf("%c",(char)(ciphertext[i]+'a'));
printf("\n");
}
void main()
{
getPlainText(); //明文
getKey(); //密钥
hill(); //加密
printCipherText(); //密文
}
以上就是关于C语言用c写一个可以验证账号,密码和修改密码的程序全部的内容,包括:C语言用c写一个可以验证账号,密码和修改密码的程序、c语言编写加密程序、c语言怎么编写hill密码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)