當前位置:首頁 » 編程語言 » des演算法代碼c語言

des演算法代碼c語言

發布時間: 2025-07-27 22:58:08

① 求祖沖之(zuc)密碼演算法演算法加密c語言實現代碼。

這么久沒人答,我都弄懂了。祖沖之演算法分3個演算法ZUC是祖沖之演算法的核心,僅產生密鍵流KS。供EEA3和EIA3調用。EEA3是加密演算法,用KS捆綁上用戶的密鑰螞畢雀,加密用戶數據D,變成密文。相當於國際上的RSA、DES、AES演算法。作用是對稱的加密解密演算法EIA3是數據完整性演算法,MAC的一種。捆綁上用數答戶的密鑰,結合KS,生成散列值。相當於國際上的HMAC結合MD5,SHA1的用法。用於密碼授權值的悶早生成和保存。

② 求一個用c語言寫的DES加密演算法~~

using system;
using system.security.cryptography;
using system.io;
using system.text;

public class encryptstringdes {

public static void main(string);
return;
}

// 使用utf8函數加密輸入參數
utf8encoding utf8encoding = new utf8encoding();
byte.tochararray());

// 方式一:調用默認的des實現方法des_csp.
des des = des.create();
// 方式二:直接使用des_csp()實現des的實體
//des_csp des = new des_csp();

// 初始化des加密的密鑰和一個隨機的、8比特的初始化向量(iv)
byte iv = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};
des.key = key;
des.iv = iv;

// 建立加密流
symmetricstreamencryptor sse = des.createencryptor();

// 使用cryptomemorystream方法獲取加密過程的輸出
cryptomemorystream cms = new cryptomemorystream();

// 將symmetricstreamencryptor流中的加密數據輸出到cryptomemorystream中
sse.setsink(cms);

// 加密完畢,將結果輸出到控制台
sse.write(inputbytearray);
sse.closestream();

// 獲取加密數據
byte);
}
console.writeline();

//上面演示了如何進行加密,下面演示如何進行解密
symmetricstreamdecryptor ssd = des.createdecryptor();
cms = new cryptomemorystream();
ssd.setsink(cms);
ssd.write(encrypteddata);
ssd.closestream();

byte decryptedchararray = utf8encoding.getchars(decrypteddata);
console.writeline("解密後數據:");
console.write(decryptedchararray);
console.writeline();
}
}

編譯

d:\csharp>csc des_demo.cs
microsoft (r) c# compiler version 7.00.8905
right (c) microsoft corp 2000. all rights reserved.

運行實例:
d:\csharp>des_demo.exe 使用c#編寫des加密程序的framework

加密結果:
3d 22 64 c6 57 d1 c4 c3 cf 77 ce 2f d0 e1 78 2a 4d ed 7a a8 83 f9 0e 14 e1 ba 38
7b 06 41 8d b5 e9 3f 00 0d c3 28 d1 f9 6d 17 4b 6e a7 41 68 40

③ C語言char des[],*p=des中這個*p是什麼意思在程序中又如何表示des[1]呢

p指向的地址就是des的地址,des[1]=*(p+1)

④ c語言,怎麼知道某一個數據在txt的第幾個位元組

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
unsigned long file_size;
char *text_buf;
FILE *fp;

fp = fopen("aa.txt","r");//這里把aa.txt改成你要打開的文件名字
fseek(fp,0,SEEK_END);
file_size = ftell(fp);
rewind(fp);
text_buf = (char *)malloc(file_size+1);
memset(text_buf,'',file_size+1);
fread(text_buf,file_size,1,fp);
char *str = "a";//這個"a"字元就是你要查找的字元
char *des;
des = strstr(text_buf,str);
int result;
result = des-text_buf+1;
printf("你查找的文字在txt的第%d位置 ",result);
}

⑤ C語言 實現逆序的Memcpy方法。

參考代碼如下:

void*reversememcpy(void*destination,constvoid*source,intnum)
{
char*des=(char*)destination,*src=(char*)source;
inti;
if(des==NULL||src==NULL||num<=0){
printf("error");
returnNULL;
}
for(i=0;i<num;++i)
des[num-i-1]=src[i];
return(void*)des;
}

⑥ C語言中handle類型是什麼意思

1、handle是句柄類型,來源於Handle-C,Handle-C是硬體描述語言。windows在創建一個系統對象的同時,把一個句柄賦值給這個實體 ,可以用這個句柄來識別或者修改這個對象, 這就是handle句柄的作用。

2、句柄(HANDLE)是資源的標識。操作系統要管理和操作這些資源,都是通過句柄來找到對應的資源。按資源的類型,又可將句柄細分成圖標句柄(HICON),游標句柄(HCURSOR),窗口句柄(HWND),應用程序實例句柄(HINSTANCE)等等各種類型的句柄。 所以HWND是一種HANDLE

⑦ des解密演算法,利用C語言解密JAVA語言加密的密碼。。密鑰為12345678,加密後的密文為:26d086be3a3a62fc

// C 語言 DES用的是 ECB模式, 沒有填充
// 因此Java端要對應, 你的明文是 liubiao 嗎?
// 另外 DES已經不安全了, 如果可以改為 3DES或者 AES吧。
public class LearnDes {

public static void main(String[] args) {
try {
System.out.println(encrypt("liubiao", "12345678"));

System.out.println(decrypt("26d086be3a3a62fc", "12345678"));
} catch (Exception e) {
e.printStackTrace();
}
}
public static String encrypt(String message, String key) throws Exception {
//Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
Cipher cipher = Cipher.getInstance("DES/ECB/NOPADDING");

DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));

SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
//cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
cipher.init(Cipher.ENCRYPT_MODE, secretKey );

return toHexString(cipher.doFinal(message.getBytes("UTF-8")));
}

public static String decrypt(String message, String key) throws Exception {

byte[] bytesrc = convertHexString(message);

//Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
Cipher cipher = Cipher.getInstance("DES/ECB/NOPADDING");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));

//cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
cipher.init(Cipher.DECRYPT_MODE, secretKey );

byte[] retByte = cipher.doFinal(bytesrc);
return new String(retByte);
}

public static byte[] convertHexString(String ss) {
byte digest[] = new byte[ss.length() / 2];
for (int i = 0; i < digest.length; i++) {
String byteString = ss.substring(2 * i, 2 * i + 2);
int byteValue = Integer.parseInt(byteString, 16);
digest[i] = (byte) byteValue;
}

return digest;
}
public static String toHexString(byte b[]) {
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String plainText = Integer.toHexString(0xff & b[i]);
if (plainText.length() < 2)
plainText = "0" + plainText;
hexString.append(plainText);
}

return hexString.toString();
}
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:587
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:882
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:575
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:761
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:678
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1006
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:251
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:108
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:799
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:706