1.å符串çå å¯ä¸è§£å¯ï¼3DESãsha1ãMD5ï¼ - swift3.1
2.VB å å¯ä¸è§£å¯çç¨åºä»£ç
3.å¦ä½ç¨JAVAå®ç°å符串ç®åå å¯è§£å¯ï¼
4.用DOS算法设置加密解密程序设计?
5.一行js代码实现字符串加密解密
6.c# å å¯ ã解å¯
å符串çå å¯ä¸è§£å¯ï¼3DESãsha1ãMD5ï¼ - swift3.1
对äºå符串çå å¯è§£å¯ï¼å¯ä»¥ç»Stringç±»æ©å±æ¹æ³ï¼æ¹ä¾¿ä½¿ç¨Swiftä¸ä½¿ç¨3DES/sha1/MD5å å¯è§£å¯ç®æ³ å¿ é¡»è¦å¼å ¥è¿ä¸ªåº - å¨æ¡¥æ¥æ件ä¸
#import <CommonCrypto/CommonCrypto.h>
3DESçå å¯æ¯å¯éçï¼ sha1åMD5çæ¯ä¸å¯éç
使ç¨æ¹æ³ï¼
ç´æ¥å¨xibçé¢æä¸ä¸ªtextFiledçæ§ä»¶ï¼ç¶åæ¾ç½®3个æé®ï¼åå«æ¯è¿è¡MD5ãsha1ã3DESå å¯ç¹å»æ¹æ³ï¼ç¶ååå«æµè¯å å¯è§£å¯æ°æ®
å¯ä»¥åèæç« blogs.com/jukaiit/p/.html
使ç¨è¿ä¸ªç¬¬ä¸æ¹æ¥å®ç° JKEncrypt
** /jukai/JKEncrypt ã
**VB å å¯ä¸è§£å¯çç¨åºä»£ç
å å¯ï¼Private Function JiaMi(ByVal varPass As String) As String 'åæ°varPassæ¯éè¦å å¯çææ¬å 容
Dim varJiaMi As String *
Dim varTmp As Double
Dim strJiaMi As String
Dim I
For I = 1 To Len(varPass)
varTmp = AscW(Mid$(varPass, I, 1))
varJiaMi = Str$(((((varTmp * 1.5) / 5.6) * 2.7) * I))
strJiaMi = strJiaMi & varJiaMi
Next I
JiaMi = strJiaMi
End Function
解å¯å½æ°ï¼
Private Function JieMi(ByVal varPass As String) As String 'åæ°varPassæ¯éè¦è§£å¯çå¯æå 容
Dim varReturn As String *
Dim varConvert As Double
Dim varFinalPass As String
Dim varKey As Integer
Dim varPasslenth As Long
varPasslenth = Len(varPass)
For I = 1 To varPasslenth /
varReturn = Mid(varPass, (I - 1) * + 1, )
varConvert = Val(Trim(varReturn))
varConvert = ((((varConvert / 1.5) * 5.6) / 2.7) / I)
varFinalPass = varFinalPass & ChrW(Val(varConvert))
Next I
JieMi = varFinalPass
End Function
æ©å±èµæï¼æ³¨æäºé¡¹
ç¼åå å¯ç¨åºï¼å°ç¨æ·è¾å ¥çä¸ä¸ªè±æå¥åå å¯ä¸ºå å¯å符串ï¼ç¶åè¾åºå å¯å符串ãå设å¥åé¿åº¦ä¸è¶ è¿ä¸ªå符ã
æ ¹æ®ç»å®çå¥åå å¯å½æ°ååSentenceEncodingï¼ç¼åå½æ°SentenceEncodingè°ç¨ç»å®çå符å å¯å½æ°CharEncodingå®æå¥åå å¯ã
ç¶åï¼ç¼å主ç¨åºæ示ç¨æ·è¾å ¥è±æå¥åï¼ç¶åè°ç¨å½æ°SentenceEncoding对å¥åå å¯ï¼æåè¾åºå å¯åçå¥åã
å符å å¯è§å为大ååæ¯åå°ååæ¯åå å¯ä¸ºå ¶è¡¥ç , æ们å®ä¹ASCIIç å¼ç¸å 为âAâ+âZâå³ç两个大ååæ¯äºä¸ºè¡¥ç ï¼ASCIIç å¼ç¸å 为âaâ+âzâå³ç两个å°ååæ¯äºä¸ºè¡¥ç ã
ç©ºæ ¼ç¨@代æ¿,å¥å·ä»¥#代æ¿,å ¶å®å符ç¨å¥ç¹ä»£æ¿ã
å½æ°ååï¼
void SentenceEncoding(char *soure,char *code);
åè½ï¼å¯¹å¾ å å¯å符串sourceå å¯åä¿åå å¯å符串å°code.
åæ°ï¼char *soureï¼æåå¾ å å¯å¥åçå符串æéï¼
char *code æåå å¯å符串çå符串æéï¼
å符å å¯å½æ°ä»£ç ã
å¦ä½ç¨JAVAå®ç°å符串ç®åå å¯è§£å¯ï¼
javaå å¯å符串å¯ä»¥ä½¿ç¨deså å¯ç®æ³ï¼å®ä¾å¦ä¸ï¼
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
/
*** å å¯è§£å¯
*
* @author shy.qiu
* @since /qiushyfm
*/
public class CryptTest {
/
*** è¿è¡MD5å å¯
*
* @param info
* è¦å å¯çä¿¡æ¯
* @return String å å¯åçå符串
*/
public String encryptToMD5(String info) {
byte[] digesta = null;
try {
// å¾å°ä¸ä¸ªmd5çæ¶æ¯æè¦
MessageDigest alga = MessageDigest.getInstance("MD5");
// æ·»å è¦è¿è¡è®¡ç®æè¦çä¿¡æ¯
alga.update(info.getBytes());
// å¾å°è¯¥æè¦
digesta = alga.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// å°æè¦è½¬ä¸ºå符串
String rs = byte2hex(digesta);
return rs;
}
/
*** è¿è¡SHAå å¯
*
* @param info
* è¦å å¯çä¿¡æ¯
* @return String å å¯åçå符串
*/
public String encryptToSHA(String info) {
byte[] digesta = null;
try {
// å¾å°ä¸ä¸ªSHA-1çæ¶æ¯æè¦
MessageDigest alga = MessageDigest.getInstance("SHA-1");
// æ·»å è¦è¿è¡è®¡ç®æè¦çä¿¡æ¯
alga.update(info.getBytes());
// å¾å°è¯¥æè¦
digesta = alga.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// å°æè¦è½¬ä¸ºå符串
String rs = byte2hex(digesta);
return rs;
}
// //////////////////////////////////////////////////////////////////////////
/
*** å建å¯å
*
* @param algorithm
* å å¯ç®æ³,å¯ç¨ DES,DESede,Blowfish
* @return SecretKey ç§å¯ï¼å¯¹ç§°ï¼å¯é¥
*/
public SecretKey createSecretKey(String algorithm) {
// 声æKeyGenerator对象
KeyGenerator keygen;
// 声æ å¯é¥å¯¹è±¡
SecretKey deskey = null;
try {
// è¿åçææå®ç®æ³çç§å¯å¯é¥ç KeyGenerator 对象
keygen = KeyGenerator.getInstance(algorithm);
// çæä¸ä¸ªå¯é¥
deskey = keygen.generateKey();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// è¿åå¯å
return deskey;
}
/
*** æ ¹æ®å¯åè¿è¡DESå å¯
*
* @param key
* å¯å
* @param info
* è¦å å¯çä¿¡æ¯
* @return String å å¯åçä¿¡æ¯
*/
public String encryptToDES(SecretKey key, String info) {
// å®ä¹ å å¯ç®æ³,å¯ç¨ DES,DESede,Blowfish
String Algorithm = "DES";
// å å¯éæºæ°çæå¨ (RNG),(å¯ä»¥ä¸å)
SecureRandom sr = new SecureRandom();
// å®ä¹è¦çæçå¯æ
byte[] cipherByte = null;
try {
// å¾å°å å¯/解å¯å¨
Cipher c1 = Cipher.getInstance(Algorithm);
// ç¨æå®çå¯é¥å模å¼åå§åCipher对象
// åæ°:(ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE,UNWRAP_MODE)
c1.init(Cipher.ENCRYPT_MODE, key, sr);
// 对è¦å å¯çå 容è¿è¡ç¼ç å¤ç,
cipherByte = c1.doFinal(info.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
// è¿åå¯æçåå è¿å¶å½¢å¼
return byte2hex(cipherByte);
}
/
*** æ ¹æ®å¯åè¿è¡DES解å¯
*
* @param key
* å¯å
* @param sInfo
* è¦è§£å¯çå¯æ
* @return String è¿å解å¯åä¿¡æ¯
*/
public String decryptByDES(SecretKey key, String sInfo) {
// å®ä¹ å å¯ç®æ³,
String Algorithm = "DES";
// å å¯éæºæ°çæå¨ (RNG)
SecureRandom sr = new SecureRandom();
byte[] cipherByte = null;
try {
// å¾å°å å¯/解å¯å¨
Cipher c1 = Cipher.getInstance(Algorithm);
// ç¨æå®çå¯é¥å模å¼åå§åCipher对象
c1.init(Cipher.DECRYPT_MODE, key, sr);
// 对è¦è§£å¯çå 容è¿è¡ç¼ç å¤ç
cipherByte = c1.doFinal(hex2byte(sInfo));
} catch (Exception e) {
e.printStackTrace();
}
// return byte2hex(cipherByte);
return new String(cipherByte);
}
// /////////////////////////////////////////////////////////////////////////////
/
*** å建å¯åç»ï¼å¹¶å°å ¬åï¼ç§åæ¾å ¥å°æå®æ件ä¸
*
* é»è®¤æ¾å ¥mykeys.batæ件ä¸
*/
public void createPairKey() {
try {
// æ ¹æ®ç¹å®çç®æ³ä¸ä¸ªå¯é¥å¯¹çæå¨
KeyPairGenerator keygen = KeyPairGenerator.getInstance("DSA");
// å å¯éæºæ°çæå¨ (RNG)
SecureRandom random = new SecureRandom();
// éæ°è®¾ç½®æ¤éæºå¯¹è±¡çç§å
random.setSeed();
// 使ç¨ç»å®çéæºæºï¼åé»è®¤çåæ°éåï¼åå§åç¡®å®å¯é¥å¤§å°çå¯é¥å¯¹çæå¨
keygen.initialize(, random);// keygen.initialize();
// çæå¯é¥ç»
KeyPair keys = keygen.generateKeyPair();
// å¾å°å ¬å
PublicKey pubkey = keys.getPublic();
// å¾å°ç§å
PrivateKey prikey = keys.getPrivate();
// å°å ¬åç§ååå ¥å°æ件å½ä¸
doObjToFile("mykeys.bat", new Object[] { prikey, pubkey });
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
/
*** å©ç¨ç§å对信æ¯è¿è¡ç¾å æç¾ååçä¿¡æ¯æ¾å ¥å°æå®çæ件ä¸
*
* @param info
* è¦ç¾åçä¿¡æ¯
* @param signfile
* åå ¥çæ件
*/
public void signToInfo(String info, String signfile) {
// ä»æ件å½ä¸è¯»åç§å
PrivateKey myprikey = (PrivateKey) getObjFromFile("mykeys.bat", 1);
// ä»æ件ä¸è¯»åå ¬å
PublicKey mypubkey = (PublicKey) getObjFromFile("mykeys.bat", 2);
try {
// Signature 对象å¯ç¨æ¥çæåéªè¯æ°åç¾å
Signature signet = Signature.getInstance("DSA");
// åå§åç¾ç½²ç¾åçç§é¥
signet.initSign(myprikey);
// æ´æ°è¦ç±åèç¾åæéªè¯çæ°æ®
signet.update(info.getBytes());
// ç¾ç½²æéªè¯æææ´æ°åèçç¾åï¼è¿åç¾å
byte[] signed = signet.sign();
// å°æ°åç¾å,å ¬å,ä¿¡æ¯æ¾å ¥æ件ä¸
doObjToFile(signfile, new Object[] { signed, mypubkey, info });
} catch (Exception e) {
e.printStackTrace();
}
}
/
*** 读åæ°åç¾åæ件 æ ¹æ®å ¬åï¼ç¾åï¼ä¿¡æ¯éªè¯ä¿¡æ¯çåæ³æ§
*
* @return true éªè¯æå false éªè¯å¤±è´¥
*/
public boolean validateSign(String signfile) {
// 读åå ¬å
PublicKey mypubkey = (PublicKey) getObjFromFile(signfile, 2);
// 读åç¾å
byte[] signed = (byte[]) getObjFromFile(signfile, 1);
// 读åä¿¡æ¯
String info = (String) getObjFromFile(signfile, 3);
try {
// åå§ä¸ä¸ªSignature对象,并ç¨å ¬é¥åç¾åè¿è¡éªè¯
Signature signetcheck = Signature.getInstance("DSA");
// åå§åéªè¯ç¾åçå ¬é¥
signetcheck.initVerify(mypubkey);
// 使ç¨æå®ç byte æ°ç»æ´æ°è¦ç¾åæéªè¯çæ°æ®
signetcheck.update(info.getBytes());
System.out.println(info);
// éªè¯ä¼ å ¥çç¾å
return signetcheck.verify(signed);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/
*** å°äºè¿å¶è½¬å为è¿å¶å符串
*
* @param b
* äºè¿å¶åèæ°ç»
* @return String
*/
public String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1) {
hs = hs + "0" + stmp;
} else {
hs = hs + stmp;
}
}
return hs.toUpperCase();
}
/
*** åå è¿å¶å符串转å为2è¿å¶
*
* @param hex
* @return
*/
public byte[] hex2byte(String hex) {
byte[] ret = new byte[8];
byte[] tmp = hex.getBytes();
for (int i = 0; i < 8; i++) {
ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
}
return ret;
}
/
*** å°ä¸¤ä¸ªASCIIå符åæä¸ä¸ªåèï¼ å¦ï¼"EF"--> 0xEF
*
* @param src0
* byte
* @param src1
* byte
* @return byte
*/
public static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 }))
.byteValue();
_b0 = (byte) (_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 }))
.byteValue();
byte ret = (byte) (_b0 ^ _b1);
return ret;
}
/
*** å°æå®ç对象åå ¥æå®çæ件
*
* @param file
* æå®åå ¥çæ件
* @param objs
* è¦åå ¥ç对象
*/
public void doObjToFile(String file, Object[] objs) {
ObjectOutputStream oos = null;
try {
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
for (int i = 0; i < objs.length; i++) {
oos.writeObject(objs[i]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/
*** è¿åå¨æ件ä¸æå®ä½ç½®ç对象
*
* @param file
* æå®çæ件
* @param i
* ä»1å¼å§
* @return
*/
public Object getObjFromFile(String file, int i) {
ObjectInputStream ois = null;
Object obj = null;
try {
FileInputStream fis = new FileInputStream(file);
ois = new ObjectInputStream(fis);
for (int j = 0; j < i; j++) {
obj = ois.readObject();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return obj;
}
/
*** æµè¯
*
* @param args
*/
public static void main(String[] args) {
CryptTest jiami = new CryptTest();
// æ§è¡MD5å å¯"Hello world!"
System.out.println("Helloç»è¿MD5:" + jiami.encryptToMD5("Hello"));
// çæä¸ä¸ªDESç®æ³çå¯å
SecretKey key = jiami.createSecretKey("DES");
// ç¨å¯åå å¯ä¿¡æ¯"Hello world!"
String str1 = jiami.encryptToDES(key, "Hello");
System.out.println("使ç¨deså å¯ä¿¡æ¯Hello为:" + str1);
// 使ç¨è¿ä¸ªå¯å解å¯
String str2 = jiami.decryptByDES(key, str1);
System.out.println("解å¯å为ï¼" + str2);
// åå»ºå ¬ååç§å
jiami.createPairKey();
// 对Hello world!使ç¨ç§åè¿è¡ç¾å
jiami.signToInfo("Hello", "mysign.bat");
// å©ç¨å ¬å对ç¾åè¿è¡éªè¯ã
if (jiami.validateSign("mysign.bat")) {
System.out.println("Success!");
} else {
System.out.println("Fail!");
}
}
}
用DOS算法设置加密解密程序设计?
以下是C 语言编写一个简单的加密解密程序。假设我们想将原始字符串中的串加每个字符按照 ASCII 码加上一个固定的偏移量,得到一个加密后的密解密源码字字符串。这个偏移量可以是符串用户指定的,也可以是加密解密程序自动生成的。下面是源码商业源码下载加密程序的代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char input[];
printf("Enter a string to encrypt: ");
scanf("%s", input);
int offset;
printf("Enter an offset: ");
scanf("%d", &offset);
for (int i = 0; i < strlen(input); i++) {
input[i] += offset;
}
printf("Encrypted string: %s\n", input);
return 0;
}
```
这个程序首先提示用户输入要加密的字符串和偏移量,然后使用一个 for 循环将字符数组中的字符每个字符加上偏移量。注意,串加在 C 语言中,密解密源码字字符可以被当作整数来处理。符串最后,加密解密程序输出加密后的源码字符串。
现在,字符我们来编写一个解密程序,串加将加密后的密解密源码字字符串解密回原始字符串。解密程序的代码如下:
```c
#include <stdio.h>
#include <string.h>
int main() {
char input[];
printf("Enter a string to decrypt: ");
scanf("%s", input);
int offset;
printf("Enter the offset: ");
scanf("%d", &offset);
for (int i = 0; i < strlen(input); i++) {
input[i] -= offset;
}
printf("Decrypted string: %s\n", input);
return 0;
}
```
这个程序与加密程序大致相同,唯一的交友cpa源码区别是在 for 循环中将字符数组中的每个字符减去偏移量。这样,解密程序就可以将加密后的字符串恢复成原始字符串了。
需要注意的是,这种简单的加密解密方式并不是非常安全,因为它可以被轻易地破解。如果您需要一个更加安全的加密算法,请使用可靠的加密库和算法。
一行js代码实现字符串加密解密
使用一行js代码实现字符串的ddos平台源码加密与解密,能够有效提升代码的简洁性与执行效率。加密与解密通常依赖于对字符进行特定的转换操作。首先,了解ASCII码字符与Unicode字符在加密与解密过程中的应用。
加密时,我们通常选择对ASCII码字符进行处理。使用`btoa`函数进行加密,它能够将字符串转换为Base编码的hibernate源码下载字节流。解密时,使用`atob`函数,它将Base编码的字节流还原为原始字符串。然而,值得注意的是,`btoa`和`atob`仅适用于ASCII码字符,对于Unicode字符可能产生不可预料的结果。
下面是web打印源码一个使用这些函数进行加密与解密的完整示例代码:
javascript
let str = "Hello, World!";
let encodedStr = btoa(str);
let decodedStr = atob(encodedStr);
console.log(encodedStr); // 输出 Base编码后的字符串
console.log(decodedStr); // 输出解密后的原始字符串
然而,对于Unicode字符的加密与解密,我们不能直接使用`btoa`和`atob`。这时,我们需使用其他方法。一种方法是通过JavaScript内置的`charCodeAt()`和`fromCharCode()`函数来实现。这些函数分别用于获取和设置字符的Unicode编码。加密时,我们对每个字符的Unicode编码增加3,解密时则减去3。最终,使用`join()`方法将处理后的字符合并成一个字符串。
以下是使用上述方法的完整示例代码:
javascript
let str = "你好,世界!";
let encodedStr = str.split('').map(char => String.fromCharCode(char.charCodeAt(0) + 3)).join('');
let decodedStr = encodedStr.split('').map(char => String.fromCharCode(char.charCodeAt(0) - 3)).join('');
console.log(encodedStr); // 输出经过处理的Unicode编码字符串
console.log(decodedStr); // 输出解密后的原始字符串
除了上述方法,还存在其他用于加密与解密的js库和框架。这些库通常提供了更复杂、更安全的加密算法,能够满足在实际开发中对加密与解密需求的多样化场景。
因此,js字符串的加密与解密可以通过多种方式实现。在选择具体实现方法时,需根据项目需求、安全级别以及性能要求来综合考虑。对于处理ASCII码字符,`btoa`和`atob`提供了一个简单且直接的解决方案;而对于Unicode字符,则需要通过内置函数或第三方库来实现更复杂且安全的加密与解密操作。
c# å å¯ ã解å¯
//é»è®¤å¯é¥åé private static byte[] Keys = { 0x, 0x, 0x, 0x, 0x, 0xAB, 0xCD, 0xEF }; /// <summary> /// DESå å¯å符串 /// </summary> /// <param name="encryptString">å¾ å å¯çå符串</param> /// <param name="encryptKey">å å¯å¯é¥,è¦æ±ä¸º8ä½</param> /// <returns>å å¯æåè¿åå å¯åçå符串ï¼å¤±è´¥è¿åæºä¸²</returns> public static string EncryptDES(string encryptString, string encryptKey) { try { byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); byte[] rgbIV = Keys; byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider(); MemoryStream mStream = new MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); return Convert.ToBaseString(mStream.ToArray()); } catch { return encryptString; } } /// <summary> /// DES解å¯å符串 /// </summary> /// <param name="decryptString">å¾ è§£å¯çå符串</param> /// <param name="decryptKey">解å¯å¯é¥,è¦æ±ä¸º8ä½,åå å¯å¯é¥ç¸å</param> /// <returns>解å¯æåè¿å解å¯åçå符串ï¼å¤±è´¥è¿æºä¸²</returns> public static string DecryptDES(string decryptString, string decryptKey) { try { byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey); byte[] rgbIV = Keys; byte[] inputByteArray = Convert.FromBaseString(decryptString); DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider(); MemoryStream mStream = new MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); return Encoding.UTF8.GetString(mStream.ToArray()); } catch { return decryptString; } } èªå®ä¹ä¸ä¸ª8ä½çå¯é¥ï¼å å¯è§£å¯çæ¶åä¸æ ·å°±å¯ä»¥äº ä¾å¦ï¼å å¯ï¼EncryptDES("è¦å å¯çå符串", "azjmerbv"); 解å¯ï¼DecryptDES("è¦è§£å¯çå符串", "azjmerbv");
VB å®ç°å符串å å¯ è§£å¯
'å¦ææ¯å°text1ä¸æ¯ä¸ªå符çascç å¼è½¬å为è¿å¶å®ç°å å¯è§£å¯å¯ä»¥è¿æ ·ï¼å¤å¶ç²è´´ä¸æ®µä»£ç
'å å¯æ°æ®
Private Sub Command1_Click()
Text2.Tag = "" 'æ¸ ç©ºtext2.tagç¨æ¥åå¨å å¯åæ°æ®
Text2.Text = "" 'æ¸ ç©ºtext2ç¨æ¥æ¾ç¤ºå å¯åæ°æ®
For i = 1 To Len(Text1.Text) 'å°text1ä¸æ¯ä¸ªå符çascç å¼è½¬å为åå è¿å¶ä»¥è½¯å车chr()åé并åå¨å¨text2.tagä¸
Text2.Tag = Text2.Tag & Hex(Asc(Mid(Text1.Text, i, 1))) & Chr() '
Next
Text2.Text = Text2.Tag 'æ¾ç¤ºå å¯åæ°æ®
End Sub
'解å¯æ°æ®
Private Sub Command2_Click()
Text1.Tag = ""
Text1.Text = ""
Dim b() As String 'å®ä¹æ°ç»ç¨æ¥åå¨ç±text1ä¸æ¯ä¸ªå符转åæ¥çåå è¿å¶æ°
b = Split(Text2.Text, Chr()) '以软å车符chr()åétext2ä¸ææ¬å¹¶åå¨å¨æ°ç»bä¸
For i = 0 To UBound(b) 'å°text2ä¸æ¯ä¸ªåå è¿å¶æ°è½¬å为åè¿å¶çascç å¼å转å为å符
Text1.Tag = Text1.Tag & Chr(Val("&h" & b(i)))
Next
Text1.Text = Text1.Tag 'æ¾ç¤ºåå§æ°æ®
End Sub
å¦ä½ä½¿ç¨JAVAå®ç°å¯¹å符串çDESå å¯å解å¯
/
*** ECB模å¼çdeså å¯ï¼ä»¥baseçç¼ç è¾åº
* @param message
* @param key
* @return
* @throws Exception
*/
public static String desEncrypt(String message, String key)throws Exception{
// DES/ECB CBC CFB OFB /PKCS5Padding NoPadding å å¯/模å¼/å¡«å
Cipher cipher = Cipher.getInstance("DES");//é»è®¤å°±æ¯ DES/ECB/PKCS5Padding
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(1, secretKey);
return new BASEEncoder().encode(cipher.doFinal(message.getBytes("UTF-8")));
}
/
*** ECB模å¼çdes解å¯
* @param message
* @param key
* @return
* @throws Exception
*/
public static String desDecrypt(String message, String key)throws Exception{
Cipher cipher = Cipher.getInstance("DES");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(2, secretKey);
return new String(cipher.doFinal(Base.decode(message)), "UTF-8");
}
ä½ èªå·±åmainæ¹æ³æµè¯ä¸ä¸ï¼åºè¯¥æ¯æ²¡é®é¢ç
Vb编程编写一个小程序,可以对输入的一段英文字符串进行加密和解密,加密算法中需要使用到学号后两位
以下是根据学号末2位加密、解密的VB程序:Private Sub Form_Click()
x = Val(Right(Text1.Text, 2)) '取学号末2位
'以下是加密
s = Text2.Text
s1 = s
For i = 1 To Len(s)
c = Mid(s1, i, 1)
Mid(s1, i, 1) = Chr(Asc(c) Xor x)
Next i
Text3.Text = s1
'以下是解密
s = s1
For i = 1 To Len(s)
c = Mid(s, i, 1)
Mid(s, i, 1) = Chr(Asc(c) Xor x)
Next i
Text4.Text = s
End Sub