c语言字符串函数源码 c语言字符串函数strcmp

如何对字符串进行MD5加密,用C语言实现,给出源代码和加密函数#include stdio.h
#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
#define R_memset(x, y, z) memset(x, y, z)
#define R_memcpy(x, y, z) memcpy(x, y, z)
#define R_memcmp(x, y, z) memcmp(x, y, z)
typedef unsigned long UINT4;
typedef unsigned char *POINTER;
typedef struct {
/*四个32bits数,用于存放最终计算得到的消息摘要.当消息长度512bits时,也用于存放每个512bits的中间结果*/
UINT4 state[4];
/*存储原始信息的bits数长度,不包括填充的bits,最长为2^64 bits*/
UINT4 count[2];
/*存放输入的信息的缓冲区,512bits*/
unsigned char buffer[64];
} MD5_CTX;
static void MD5Transform(UINT4[4], unsigned char[64]);
static void Encode(unsigned char *, UINT4 *, unsigned int);
static void Decode(UINT4 *, unsigned char *, unsigned int);
/*
用于bits填充的缓冲区,当欲加密的信息的bits数被512除其余数为448时,需要填充的bits的最大值为512=64*8*/
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
};
/*接下来的这几个宏定义是md5算法规定的,就是对信息进行md5加密都要做的运算*/
#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);\
}
求C语言将十六进制字符串转换为整型int的函数源代码,要求不能用库函数?/*
请输入十六进制数 : 120
十 六 进 制 数: 120
十进制数: 288
Press any key to continue
*/
#include ctype.h
#include stdio.h
#define MAX 10
#define NewLine 10
main () {
char num16[MAX];
unsigned long cocnvertfactor = 1,num10 = 0;
char ch,j,i = 0;
printf("请输入十六进制数 : ");
while (((ch = getchar()) != NewLine)(iMAX))
if ((ch = '0'ch = '9') || (ch = 'A'ch = 'F') || (ch = 'a'ch = 'f'))
num16[i] = ch;// 仅接收数字和英文前6个字母
for (j = 0;ji;j) num16[j] = toupper(num16[j]);// 小写字母转换成大写,其他字符不变
for (j = i - 1;j = 0;j--) {// 开始转换
if (isalpha(num16[j])) num10 = num10cocnvertfactor*(num16[j] - 'A'10);
else num10 = num10cocnvertfactor*(num16[j] - '0');
cocnvertfactor = 16*cocnvertfactor;
}
printf("\n十 六 进 制 数: ");
for (j = 0;ji;j) printf("%c",num16[j]);
printf("\n十进制数: \u\n\n\n",num10);
}
C语言:几个简单的字符串函数//每个函数运行c语言字符串函数源码 , input char从键盘输入一个要处理的字符串c语言字符串函数源码 , 此程序在vc6.0上编译运行都通过
#include stdio.h
fun1(char a[100])
{
char ch;
int n,i=0;
printf("input char:\n");
ch=getchar();
while(ch!='\n')
{
a[i]=ch;
ch=getchar();
}
n=i;
for(i=0;in;i)
if(a[i]!=a[i 1])
printf("%c",a[i]);
}
fun2(char a[100])
{
char ch;
int n,i=0;
printf("input char:\n");
ch=getchar();
while(ch!='\n')
{
a[i]=ch;
ch=getchar();
}
n=i;
for(i=0;i3;i)
if('a'=a[i]='z')
printf("%c",a[i]-32);
else
printf("%c",a[i]);
printf("\n");
}
fun3(char a[100])
{
char ch;
int n,i=0;
printf("input char:\n");
ch=getchar();
while(ch!='\n')
{
a[i]=ch;
ch=getchar();
}
n=i;
printf("%d\n",n);
}
fun4(char a[100])
{
char ch;
int n,i=0;
printf("input char:\n");
ch=getchar();
while(ch!='\n')
{
a[i]=ch;
ch=getchar();
}
n=i;
for(i=n-1;i=0;i--)
printf("%c",a[i]);
}
main()
{
char a[100],b[100],c[100];
fun1(a);
fun2(a);
fun3(b);
fun4(c);
}
怎样用c语言编写将字符串转换为整数的函数具体的方法是:循环处理字符字符串中的每个字符,将其转化为相应的数,然后加起来,最后就可以得到转化后的整数 我这个程序可以处理字符串范围为长整型的取值范围 这个函数源码如下: ------------------------------------------------------------------ long toInteger( char* str ) { long result = 0; int len; int i = 0; long tmp; len = strlen( str ); while ( ilen ) { tmp = *str- '0'; if ( 9tmp ) { printf( "\"%c\" is not a number!\n" , tmp'0' ); break; } tmp *= pow( 10 , len - i - 1 ); result= tmp; i; } return result; } 本函数可以对输入的字符串进行错误识别,若包含非数字字符则报错(函数没有考虑输入为负数) 关于这个函数的使用方法,以下为一个例子 程序源代码如下,已通过调试编译 , 可以运行: ---------------------------------------------------------------------- #include "stdio.h" #include "math.h" #include "string.h" long toInteger( char* str ); int main() { char* str = "123456"; long a; clrscr(); a = toInteger( str ); printf( "%ld\n" , a ); return 0; } long toInteger( char* str ) { long result = 0; int len; int i = 0; long tmp; len = strlen( str ); while ( ilen ) { tmp = *str- '0'; if ( 9tmp ) { printf( "\"%c\" is not a number!\n" , tmp'0' ); break; } tmp *= pow( 10 , len - i - 1 ); result= tmp; i; } return result; }
C语言 字符串查找(要代码)用strstr这个函数
包含文件:string.h
函数名: strstr
函数原型:extern char *strstr(char *str1, char *str2);
功能:找出str2字符串在str1字符串中第一次出现c语言字符串函数源码的位置(不包括str2c语言字符串函数源码的串结束符) 。
返回值:返回该位置的指针c语言字符串函数源码,如找不到 , 返回空指针 。
源代码:
#includestdio.h
#includestring.h//调用string.h中的strstr函数
void main(){
char ch1[255]="abcde";
char ch2[100]="cd";
char* ch;//用于接受返回值
if((ch=strstr(ch1,ch2))==NULL){//说明没有要找的字符串
printf("-1\n");
}else{//说明找到c语言字符串函数源码了那个字符串
printf("%d\n",ch-ch1 1);//cde的地址减去abcde的地址 1
}
}
编写函数完成字符串的加密与解密(c语言)?C语言代码和运行结果如下:
输出符合示例,加解密均正确 , 望采纳~
附源码链接:字符串加解密
【c语言字符串函数源码 c语言字符串函数strcmp】关于c语言字符串函数源码和c语言字符串函数strcmp的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读