【reboot命令 源码】【源码 会员】【源码合唱】base64decoder 源码
1.这个(base64编码)音频数据怎么用?
2.å¨Javaä¸å¦ä½è¿è¡BASE64ç¼ç å解ç
3.java base64decoder
4.Java中用Base64编程的reboot命令 源码文件批量加密解密工具程序代码
5.å¦ä½ä½¿ç¨JAVAå®ç°å¯¹å符串çDESå å¯å解å¯
6.Base64ç¼ç 解ç åç
这个(base64编码)音频数据怎么用?
import java.io.File;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;
import sun.misc.BASEDecoder;
import sun.misc.BASEEncoder;
public class base {
public static String getWAVString(){
File fi = new File("click.wav");
if (!fi.exists())
return "";
byte[] data = null;
try{
InputStream is = new FileInputStream(fi);
data = new byte[is.available()];
is.read(data);
is.close();
}catch(Exception ex){
ex.printStackTrace();
}
BASEEncoder encoder = new BASEEncoder();
return encoder.encode(data);
}
public static void getWAV(){
BASEDecoder decoder = new BASEDecoder();
try{
byte[] data = decoder.decodeBuffer(WAVString);
/*for(int i=0 ;i<data.length;i++){
if (data[i] < 0) {
data[i] += ;
}
}*/
OutputStream out = new FileOutputStream("click_BASE.wav");
out.write(data);
out.flush();
out.close();
}catch(Exception ex){
}
}
public static void main(String[] args){
WAVString = getWAVString();
try{
FileWriter out = new FileWriter("Click_BASEString.txt");
out.write(WAVString);
out.flush();
out.close();
}catch(Exception ex){
}
getWAV();
}
private static String WAVString;
}
å¨Javaä¸å¦ä½è¿è¡BASEç¼ç å解ç
import sun.misc.BASEEncoder;
import sun.misc.BASEDecoder;
// å° s è¿è¡ BASE ç¼ç
public static String getBASE(String s) {
if (s == null) return null;
return (new sun.misc.BASEEncoder()).encode( s.getBytes() );
}
// å° BASE ç¼ç çå符串 s è¿è¡è§£ç
public static String getFromBASE(String s) {
if (s == null) return null;
BASEDecoder decoder = new BASEDecoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
java basedecoder
java basedecoderæ¯ä»ä¹ï¼è®©æ们ä¸èµ·äºè§£ä¸ä¸ï¼
decoderæ¯java baseç解ç ï¼å¯ä»¥ç¨Javaç¨å¼è¯è¨æ¥å®æBaseçç¼ç ä¸è§£ç åè½ï¼å¨å®é åºç¨ä¸ï¼Baseé¤äºè½å°Binaryèµæå¯è§åä¹å¤ï¼ä¹å¸¸ç¨æ¥è¡¨ç¤ºå串å å¯è¿åçå 容ã
é£ä¹å¨Javaä¸å¦ä½åBaseçç¼ç ä¸è§£ç ï¼decoderï¼ï¼å¯å为两个æ¶æã
æ©æåæ³ï¼
æ©æå¨Javaä¸åBaseçç¼ç ä¸è§£ç ï¼ä¼ä½¿ç¨å°JDKésun.miscå¥ä»¶ä¸çBASEEncoderåBASEDecoderè¿ä¸¤ä¸ªç±»å«ï¼ç¨æ³å¦ä¸ï¼
final BASEEncoder encoder = new BASEEncoder(); final BASEDecoder decoder = new BASEDecoder(); final String text = "å串æå"; final byte[] textByte = text.getBytes("UTF-8"); //ç¼ç final String encodedText = encoder.encode(textByte); System.out.println(encodedText); //解ç System.out.println(new String(decoder.decodeBuffer(encodedText), "UTF-8"));
åæåæ³ï¼
å¨Java 8çjava.utilå¥ä»¶ä¸ï¼æ°å¢äºBaseçç±»å«ï¼å¯ä»¥ç¨æ¥å¤çBaseçç¼ç ä¸è§£ç ï¼ç¨æ³å¦ä¸ï¼ package com.lmp.utils; import sun.misc.BASEDecoder; import sun.misc.BASEEncoder; public class test { public static void main(String[] args) throws Exception { String str = "hello word"; BASEEncoder baseEncoder = new BASEEncoder(); // JDK1.8 BASEEncoder å å¯ String encode = baseEncoder.encode(str.getBytes()); System.out.println(encode); BASEDecoder baseDecoder = new BASEDecoder(); // JDK1.8 BASEDecoder è§£å¯ byte[] bytes = baseDecoder.decodeBuffer(encode); String res = new String(bytes); System.out.println(res); } }
Java中用Base编程的文件批量加密解密工具程序代码
/** * BASE解密 * * @param key * @return * @throws Exception */
public static byte[] decryptBASE(String key) throws Exception { return (new BASEDecoder()).decodeBuffer(key); } /** * BASE加密 * * @param key * @return * @throws Exception */ public static String encryptBASE(byte[] key) throws Exception { return (new BASEEncoder()).encodeBuffer(key); }
å¦ä½ä½¿ç¨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æ¹æ³æµè¯ä¸ä¸ï¼åºè¯¥æ¯æ²¡é®é¢ç
Baseç¼ç 解ç åç
Baseç¼ç ä¸è§£ç åçæ¶åçç®æ³1ãçé¤æ³
çé¤æ³è¿ç®æ¹æ³æ¯å ç¨ä¸ä¸ªé¤æ°é¤ä»¥è½è¢«å®é¤å°½çä¸ä¸ªè´¨æ°ï¼ä»¥æ¤ç±»æ¨ï¼é¤å°åæ¯è´¨æ°ä¸ºæ¢ãéè¿çé¤æ³ï¼åè¿å¶æ°å¯ä»¥ä¸æé¤ä»¥2å¾å°å¤ä¸ªä½æ°ãæåï¼å°ä½æ°ä»ä¸å°ä¸è¿è¡æåç»åï¼å¾å°äºè¿å¶æ°ã
å®ä¾ï¼ä»¥å符n对åºçascIIç¼ç 为ä¾ã
/ 2= .../ 2= .../ 2= .../ 2= 6... / 2= 3... / 2= 1... / 2= 0...1å°ä½æ°ä»ä¸å°ä¸è¿è¡æåç»åï¼å¾å°å符n对åºçascIIç¼ç 转äºè¿å¶ä¸ºï¼å 为ä¸åè对åº8ä½(bit), æ以éè¦ååè¡¥0补足8ä½ï¼å¾å°ãå ¶ä½å符åçå¯å¾ã
2ãææå±å¼æ±åææå±å¼æ±å, 8ä½äºè¿å¶æ°ä»å³å°å·¦ï¼æ¬¡æ°æ¯0å°7ä¾æ¬¡éå¢, åºæ°åºæ°æ¬¡æ°ï¼ä»å·¦å°å³ä¾æ¬¡ç´¯å ï¼ç¸å ç»æ为对åºåè¿å¶æ°ãæ们已äºè¿å¶æ°è½¬è¿å¶ä¸ºä¾ï¼ $$ ()_2 = ^0 + ^ 1 + ^2 + ^3 + ^4 + ^5 + ^6 + 0 * 2^7 $$
3ãä½æ¦å¿µäºè¿å¶æ°ç³»ç»ä¸ï¼æ¯ä¸ª0æ1å°±æ¯ä¸ä¸ªä½(bitï¼æ¯ç¹)ï¼ä¹å«åå¨åå ï¼ä½æ¯æ°æ®åå¨çæå°åä½ãå ¶ä¸ 8bit 就称为ä¸ä¸ªåèï¼Byteï¼ã
4ã移ä½è¿ç®ç¬¦ç§»ä½è¿ç®ç¬¦å¨ç¨åºè®¾è®¡ä¸ï¼æ¯ä½æä½è¿ç®ç¬¦çä¸ç§ã移ä½è¿ç®ç¬¦å¯ä»¥å¨äºè¿å¶çåºç¡ä¸å¯¹æ°åè¿è¡å¹³ç§»ãæç §å¹³ç§»çæ¹ååå¡«å æ°åçè§åå为ä¸ç§ï¼<<(左移)ã>>(带符å·å³ç§»)å>>>(æ 符å·å³ç§»)ãå¨baseçç¼ç å解ç è¿ç¨ä¸æä½çæ¯æ£æ°ï¼æä»¥ä» ä½¿ç¨<<(左移)ã>>(带符å·å³ç§»)两ç§è¿ç®ç¬¦ã
左移è¿ç®ï¼æ¯å°ä¸ä¸ªäºè¿å¶ä½çæä½æ°ææå®ç§»å¨çä½æ°å左移å¨ï¼ç§»åºä½è¢«ä¸¢å¼ï¼å³è¾¹ç§»åºç空ä½ä¸å¾è¡¥0ãã左移ç¸å½äºä¸ä¸ªæ°ä¹ä»¥2ç次æ¹ã
å³ç§»è¿ç®ï¼æ¯å°ä¸ä¸ªäºè¿å¶ä½çæä½æ°ææå®ç§»å¨çä½æ°åå³ç§»å¨ï¼ç§»åºä½è¢«ä¸¢å¼ï¼å·¦è¾¹ç§»åºç空ä½ä¸å¾è¡¥0ï¼æè 补符å·ä½ï¼è¿ç±ä¸åçæºå¨èå®ãå¨ä½¿ç¨è¡¥ç ä½ä¸ºæºå¨æ°çæºå¨ä¸ï¼æ£æ°ç符å·ä½ä¸º0ï¼è´æ°ç符å·ä½ä¸º1ããå³ç§»ç¸å½äºä¸ä¸ªæ°é¤ä»¥2ç次æ¹ã
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)5ãä¸è¿ç®ãæè¿ç®ä¸è¿ç®ãæè¿ç®é½æ¯è®¡ç®æºä¸ä¸ç§åºæ¬çé»è¾è¿ç®æ¹å¼ã
ä¸è¿ç®ï¼ç¬¦å·è¡¨ç¤ºä¸º&ãè¿ç®è§åï¼ä¸¤ä½åæ¶ä¸ºâ1âï¼ç»ææ为â1âï¼å¦å为0
æè¿ç®ï¼ç¬¦å·è¡¨ç¤ºä¸ºï½ãè¿ç®è§åï¼ä¸¤ä½åªè¦æä¸ä½ä¸ºâ1âï¼ç»æ就为â1âï¼å¦å为0
ä»ä¹æ¯baseç¼ç $$\ 2^6=\ $$
\
Baseç¼ç æ¯å°å符串以æ¯3个8æ¯ç¹(bit)çåèååºåæåæ4个6æ¯ç¹(bit)çåè(6æ¯ç¹ææåèï¼æ左边两个永è¿ä¸º0ï¼å ¶å®ä¹æ¯8æ¯ç¹çåè)ååºåï¼åå°å¾å°çååºåæ¥æ¾Baseçç¼ç ç´¢å¼è¡¨ï¼å¾å°å¯¹åºçå符æ¼æ¥ææ°çå符串çä¸ç§ç¼ç æ¹å¼ã
æ¯3个8æ¯ç¹(bit)çåèååºåæåæ4个6æ¯ç¹(bit)çåèçæåè¿ç¨å¦ä¸å¾æ示ï¼
为ä»ä¹baseç¼ç åç大å°æ¯åæ¥ç4/3åå 为6å8çæå¤§å ¬åæ°æ¯ï¼æ以3个8æ¯ç¹çåèå好å¯ä»¥æåæ4个6æ¯ç¹çåèï¼3 x 8 = 6 x 4ã计ç®æºä¸ï¼å 为ä¸ä¸ªåèéè¦8个åå¨åå åå¨ï¼æ以æ们è¦æ6个æ¯ç¹å¾åé¢è¡¥ä¸¤ä½0ï¼è¡¥è¶³8个æ¯ç¹ãå¦ä¸å¾æ示ï¼
补足åæéçåå¨åå 为个ï¼æ¯åæ¥æéç个ç4/3åãè¿ä¹å°±æ¯baseç¼ç åç大å°æ¯åæ¥ç4/3åçåå ã
为ä»ä¹å½å为baseå¢ï¼å 为6ä½(bit)çäºè¿å¶æ°æ2ç6次æ¹ä¸ª,ä¹å°±æ¯äºè¿å¶æ°(-)ä¹é´ç代表0-ç个äºè¿å¶æ°ã
ä¸æ¯è¯´ä¸ä¸ªåèæ¯ç¨8ä½äºè¿å¶è¡¨ç¤ºçåï¼ä¸ºä»ä¹ä¸æ¯2ç8次æ¹ï¼å 为æ们å¾å°ç8ä½äºè¿å¶æ°çå两ä½æ°¸è¿æ¯0ï¼çæ£çææä½åªæ6ä½ï¼æ以æ们æè½å¤å¾å°çäºè¿å¶æ°åªæ2ç6次æ¹ä¸ªã
Baseå符æ¯åªä¸ªï¼Baseçç¼ç ç´¢å¼è¡¨ï¼å符éç¨äº"A-Zãa-zã0-9ã+ã/" 个å¯æå°å符æ¥ä»£è¡¨(-)è¿ä¸ªäºè¿å¶æ°ãå³
let baseEncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'ç¼ç åçè¦æ3个åèæåæ4个åèå¯ä»¥æä¹åï¼
æµç¨å¾æè·¯åææ å°å ³ç³»ï¼abc â xyziãæ们ä»é«ä½å°ä½ä½æ·»å ç´¢å¼æ¥åæè¿ä¸ªè¿ç¨
x: (åé¢è¡¥ä¸¤ä¸ª0)açåå ä½ => a7a6a5a4a3a2
y: (åé¢è¡¥ä¸¤ä¸ª0)açåä¸¤ä½ + bçååä½ => a1a0b7b6b5b4
z: (åé¢è¡¥ä¸¤ä¸ª0)bçååä½ + cçåä¸¤ä½ => b3b2b1b0c7c6
i: (åé¢è¡¥ä¸¤ä¸ª0)cçåå ä½ => c5c4c3c2c1c0
éè¿ä¸è¿°çæ å°å ³ç³»ï¼å¾å°å®ç°æè·¯ï¼
å°å符对åºçAscIIç¼ç 转为8ä½äºè¿å¶æ°
å°æ¯ä¸ä¸ª8ä½äºè¿å¶æ°è¿è¡ä»¥ä¸æä½
å°ç¬¬ä¸ä¸ªæ°å³ç§»ä½2ä½ï¼å¾å°ç¬¬ä¸ä¸ª6ä½ææä½äºè¿å¶æ°
å°ç¬¬ä¸ä¸ªæ° & 0x3ä¹å左移ä½4ä½ï¼å¾å°ç¬¬äºä¸ª6ä½ææä½äºè¿å¶æ°ç第ä¸ä¸ªå第äºä¸ªææä½ï¼å°ç¬¬äºä¸ªæ° & 0xf0ä¹åå³ç§»ä½4ä½ï¼å¾å°ç¬¬äºä¸ª6ä½ææä½äºè¿å¶æ°çååä½ææä½ï¼ä¸¤è åä¸å¾å°ç¬¬äºä¸ª6ä½ææä½äºè¿å¶
å°ç¬¬äºä¸ªæ° & 0xfä¹å左移ä½2ä½ï¼å¾å°ç¬¬ä¸ä¸ª6ä½ææä½äºè¿å¶æ°çååä½ææä½ï¼å°ç¬¬ä¸ä¸ªæ° & 0xC0ä¹åå³ç§»ä½6ä½ï¼å¾å°ç¬¬ä¸ä¸ª6ä½ææä½äºè¿å¶æ°çå两ä½ææä½ï¼ä¸¤è åä¸å¾å°ç¬¬ä¸ä¸ª6ä½ææä½äºè¿å¶
å°ç¬¬ä¸ä¸ªæ° & 0x3fï¼å¾å°ç¬¬å个6ä½ææä½äºè¿å¶æ°
å°è·å¾ç6ä½ææä½äºè¿å¶æ°è½¬åè¿å¶ï¼æ¥æ¾å¯¹åbaseå符
代ç å®ç°ä»¥haoå符串为ä¾ï¼è§å¯baseç¼ç çè¿ç¨ï¼å°ä¸é¢è½¬æ¢éè¿ä»£ç é»è¾åæå®ç°
// è¾å ¥å符串let str = 'hao'// baseå符串let baseEncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'// å®ä¹è¾å ¥ãè¾åºåèçäºè¿å¶æ°let char1, char2, char3, out1, out2, out3, out4, out// å°å符对åºçascIIç¼ç 转为8ä½äºè¿å¶æ°char1 = str.charCodeAt(0) & 0xff // char2 = str.charCodeAt(1) & 0xff // char3 = str.charCodeAt(2) & 0xff // // è¾åº6ä½ææåèäºè¿å¶æ°out1 = char1 >> 2 // out2 = (char1 & 0x3) << 4 | (char2 & 0xf0) >> 4 // out3 = (char2 & 0xf) << 2 | (char3 & 0xc0) >> 6 // out4 = char3 & 0x3f // out = baseEncodeChars[out1] + baseEncodeChars[out2] + baseEncodeChars[out3] + baseEncodeChars[out4] // aGFvç®æ³åæout1: char1 >> 2
->out2 = (char1 & 0x3) << 4 | (char2 & 0xf0) >> 4
// ä¸è¿ç®----------------// 移ä½è¿ç®åå¾// æè¿ç®--------第ä¸ä¸ªå符第å个å符åç
æ´çä¸è¿°ä»£ç ï¼æ©å±è³å¤å符å符串
// è¾å ¥å符串let str = 'haohaohao'// baseå符串let baseEncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'// è·åå符串é¿åº¦let len = str.length// å½åå符索å¼let index = 0// è¾åºå符串let out = ''while(index < len) { // å®ä¹è¾å ¥ãè¾åºåèçäºè¿å¶æ°let char1, char2, char3, out1, out2, out3, out4// å°å符对åºçascIIç¼ç 转为8ä½äºè¿å¶æ°char1 = str.charCodeAt(index++) & 0xff // char2 = str.charCodeAt(index++) & 0xff // char3 = str.charCodeAt(index++) & 0xff // // è¾åº6ä½ææåèäºè¿å¶æ°out1 = char1 >> 2 // out2 = (char1 & 0x3) << 4 | (char2 & 0xf0) >> 4 // out3 = (char2 & 0xf) << 2 | (char3 & 0xc0) >> 6 // out4 = char3 & 0x3f // out = out + baseEncodeChars[out1] + baseEncodeChars[out2] + baseEncodeChars[out3] + baseEncodeChars[out4] // aGFv}åå符串é¿åº¦ä¸æ¯3çæ´åæ°çæ åµï¼éè¦ç¹æ®å¤ç
...char1 = str.charCodeAt(index++) & 0xff // if (index == len) { out2 = (char1 & 0x3) << 4out = out + baseEncodeChars[out1] + baseEncodeChars[out2] + '=='return out}char2 = str.charCodeAt(index++) & 0xff // if (index == len) { out1 = char1 >> 2 // out2 = (char1 & 0x3) << 4 | (char2 & 0xf0) >> 4 // out3 = (char2 & 0xf) << 2out = out + baseEncodeChars[out1] + baseEncodeChars[out2] + baseEncodeChars[out3] + '='return out}...å ¨é¨ä»£ç
function baseEncode(str) { // baseå符串let baseEncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'// è·åå符串é¿åº¦let len = str.length// å½åå符索å¼let index = 0// è¾åºå符串let out = ''while(index < len) { // å®ä¹è¾å ¥ãè¾åºåèçäºè¿å¶æ°let char1, char2, char3, out1, out2, out3, out4// å°å符对åºçascIIç¼ç 转为8ä½äºè¿å¶æ°char1 = str.charCodeAt(index++) & 0xffout1 = char1 >> 2if (index == len) { out2 = (char1 & 0x3) << 4out = out + baseEncodeChars[out1] + baseEncodeChars[out2] + '=='return out}char2 = str.charCodeAt(index++) & 0xffout2 = (char1 & 0x3) << 4 | (char2 & 0xf0) >> 4 if (index == len) { out3 = (char2 & 0xf) << 2out = out + baseEncodeChars[out1] + baseEncodeChars[out2] + baseEncodeChars[out3] + '='return out}char3 = str.charCodeAt(index++) & 0xff// è¾åº6ä½ææåèäºè¿å¶æ°out3 = (char2 & 0xf) << 2 | (char3 & 0xc0) >> 6out4 = char3 & 0x3fout = out + baseEncodeChars[out1] + baseEncodeChars[out2] + baseEncodeChars[out3] + baseEncodeChars[out4]}return out}baseEncode('haohao') // aGFvaGFvbaseEncode('haoha') // aGFvaGE=baseEncode('haoh') // aGFvaA==解ç åçéåæ¨å¯¼ï¼ç±æ¯4个6ä½ææä½çäºè¿å¶æ°å并æ3个8ä½äºè¿å¶æ°ï¼æ ¹æ®ascIIç¼ç æ å°å°å¯¹åºå符åæ¼æ¥å符串
æè·¯åææ å°å ³ç³» xyzi -> abc
a: xåå ä½ + y第ä¸ãåä½ => x5x4x3x2x1x0y5y4
b: yååä½ + z第ä¸ãåãäºãå ä½ => y3y2y1y0z5z4z3z2
c: zåä¸¤ä½ + iåå ä½ => z1z0i5i4i3i2i1i0
å°å符对åºçbaseå符éçç´¢å¼è½¬ä¸º6ä½ææä½äºè¿å¶æ°
å°æ¯å个6ä½ææä½äºè¿å¶æ°è¿è¡ä»¥ä¸æä½
第ä¸ä¸ªäºè¿å¶æ°å·¦ç§»ä½2ä½ï¼å¾å°æ°äºè¿å¶æ°çå6ä½ï¼ç¬¬äºä¸ªäºè¿å¶æ° & 0xä¹åå³ç§»ä½4ä½ï¼åæéå¾å°ç¬¬ä¸ä¸ªæ°äºè¿å¶æ°
第äºä¸ªäºè¿å¶æ° & 0xfä¹å左移ä½4ä½ï¼ç¬¬ä¸ä¸ªäºè¿å¶æ° & 0x3cä¹åå³ç§»ä½2ä½ï¼åæéå¾å°ç¬¬äºä¸ªæ°äºè¿å¶æ°
第äºä¸ªäºè¿å¶æ° & 0x3ä¹å左移ä½6ä½ï¼ä¸ç¬¬å个äºè¿å¶æ°åæéå¾å°ç¬¬äºä¸ªæ°äºè¿å¶æ°
æ ¹æ®ascIIç¼ç æ å°å°å¯¹åºå符åæ¼æ¥å符串
代ç å®ç°// baseå符串let str = 'aGFv'// baseå符élet baseCharsArr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'.split('')// è·åç´¢å¼å¼let char1 = baseCharsArr.findIndex(char => char==str[0]) & 0xff // let char2 = baseCharsArr.findIndex(char => char==str[1]) & 0xff // let char3 = baseCharsArr.findIndex(char => char==str[2]) & 0xff // let char4 = baseCharsArr.findIndex(char => char==str[3]) & 0xff // let out1, out2, out3, out// ä½è¿ç®out1 = char1 << 2 | (char2 & 0x) >> 4out2 = (char2 & 0xf) << 4 | (char3 & 0x3c) >> 2out3 = (char3 & 0x3) << 6 | char4console.log(out1, out2, out3)out = String.fromCharCode(out1) + String.fromCharCode(out2) + String.fromCharCode(out3)éå°æç¨'='è¡¥è¿ä½çæ åµæ¶
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)0解ç æ´ä¸ªå符串ï¼æ´ç代ç å
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)1ä¸è¿°è§£ç æ ¸å¿æ¯å符ä¸baseå符éç´¢å¼çæ å°ï¼ç½ä¸çå°è¿ä½¿ç¨AscIIç¼ç ç´¢å¼æ å°baseå符索å¼çæ¹æ³
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)2ç±æ¤å¯è§ï¼baseDecodeCharså¯¹ç §accIIç¼ç 表çç´¢å¼åæ¾çæ¯baseç¼ç 表ç对åºå符çç´¢å¼ã
jdk1.8ä¹åçæ¹å¼Baseç¼ç ä¸è§£ç æ¶ï¼ä¼ä½¿ç¨å°JDKésun.miscå å¥ä»¶ä¸çBASEEncoderç±»åBASEDecoderç±»
sun.miscå ææä¾çBaseç¼ç 解ç åè½æçä¸é«ï¼å æ¤å¨1.8ä¹åçjdkçæ¬å·²ç»è¢«å é¤äº
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)3Apache Commons Codecå çæ¹å¼Apache Commons Codec ææä¾Baseçç¼ç ä¸è§£ç åè½ï¼ä¼ä½¿ç¨å° org.apache.commons.codec.binary å¥ä»¶ä¸çBaseç±»å«ï¼ç¨æ³å¦ä¸
1ãå¼å ¥ä¾èµ
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)42ã代ç å®ç°
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)5jdk1.8ä¹åçæ¹å¼ä¸sun.miscå åApache Commons Codecææä¾çBaseç¼è§£ç å¨æ¹å¼æ¥æ¯è¾ï¼Java 8æä¾çBaseæ¥ææ´å¥½çæè½ãå®é æµè¯ç¼ç ä¸è§£ç é度ï¼Java 8æä¾çBaseï¼è¦æ¯ sun.misc å¥ä»¶æä¾çè¿è¦å¿«è³å°åï¼æ¯ Apache Commons Codec æä¾çè¿è¦å¿«è³å°3åã
// 左移 << 2 -> (左侧移åºä½è¢«ä¸¢å¼) -> (å³ä¾§ç©ºä½ä¸å¾è¡¥0)// å³ç§» >> 2 -> (å³ä¾§ç§»åºä½è¢«ä¸¢å¼) -> (左侧空ä½ä¸å¾è¡¥0)6æ»ç»Base æ¯ä¸ç§æ°æ®ç¼ç æ¹å¼ï¼å¯åç®åå å¯ä½¿ç¨ï¼å¯ä»¥téè¿æ¹åbaseç¼ç æ å°é¡ºåºæ¥å½¢æèªå·±ç¬ç¹çå å¯ç®æ³è¿è¡å å¯è§£å¯ã
ç¼ç 表Baseç¼ç 表AscIIç ç¼ç 表åæï¼/post/