|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『楼 主』:
[思路挑战][讨论]批处理做 Base64 编码运算 理论原型
使用 LLM 解释/回答一下
::base64conv.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal enabledelayedexpansion
set code=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set /A B1=10,B2=0x7f,B3=255
echo %B1% %B2% %B3%
:: byte-triplet to base64-quadruple 第一次echo要encode的几个ASCII字符
set /A Q1=(%B1% "&" 252) ">>" 2
set /A Q2=((%B1% "&" 3) "<<" 4) + ((%B2% "&" 240) ">>" 4)
set /A Q3=((%B2% "&" 15) "<<" 2) + ((%B3% "&" 192) ">>" 6)
set /A Q4=(%B3% "&" 63)
::
echo %Q1% %Q2% %Q3% %Q4% 第二次echo已经encode完毕
echo !code:~%Q1%,1! !code:~%Q2%,1! !code:~%Q3%,1! !code:~%Q4%,1!
:: base64-quadruple to byte-triplet 第三次echo Base64字符流出来了!
:: yes, I know, to work a loop to find the pos in %code% should be here.
set /A B1=(%Q1% "<<" 2) + ((%Q2% "&" 48) ">>" 4)
set /A B2=((%Q2% "&" 15) "<<" 4) + ((%Q3% "&" 60) ">>" 2)
set /A B3=((%Q3% "&" 3) "<<" 6) + %Q4%
::
echo %B1% %B2% %B3% 第四次echo decode到原来的字符
::base64conv.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
可见 set /a 的位运算的强大了!以上代码我完全没有看懂,详情见
http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/cfe3dbf991d68187/b03cb66dd08c2719?lnk=gst&q=base64&rnum=1#b03cb66dd08c2719
各位 版主、 高手、 潜水的大侠都出来想想怎么实现用纯批处理做BASE64编码/解码?
做Base64的算法理论研究是十分有用的,很简单的例子就是:批处理加密,二进制文件嵌入bat,处理EMail,等等。
Last edited by electronixtar on 2006-11-15 at 01:25 AM ]
::base64conv.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal enabledelayedexpansion
set code=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set /A B1=10,B2=0x7f,B3=255
echo %B1% %B2% %B3%
:: Byte-triplet to base64-quadruple First echo the ASCII characters to be encoded
set /A Q1=(%B1% "&" 252) ">>" 2
set /A Q2=((%B1% "&" 3) "<<" 4) + ((%B2% "&" 240) ">>" 4)
set /A Q3=((%B2% "&" 15) "<<" 2) + ((%B3% "&" 192) ">>" 6)
set /A Q4=(%B3% "&" 63)
::
echo %Q1% %Q2% %Q3% %Q4% Second echo completed encoding
echo !code:~%Q1%,1! !code:~%Q2%,1! !code:~%Q3%,1! !code:~%Q4%,1!
:: Base64-quadruple to byte-triplet Third echo The Base64 characters are out!
:: yes, I know, to work a loop to find the pos in %code% should be here.
set /A B1=(%Q1% "<<" 2) + ((%Q2% "&" 48) ">>" 4)
set /A B2=((%Q2% "&" 15) "<<" 4) + ((%Q3% "&" 60) ">>" 2)
set /A B3=((%Q3% "&" 3) "<<" 6) + %Q4%
::
echo %B1% %B2% %B3% Fourth echo decoded to the original character
::base64conv.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
It can be seen that the bit operations of set /a are powerful! I don't understand the above code at all. For details, see
http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/cfe3dbf991d68187/b03cb66dd08c2719?lnk=gst&q=base64&rnum=1#b03cb66dd08c2719
Moderators, experts, and lurkers here, come out and think about how to implement BASE64 encoding/decoding with pure batch processing?
The theoretical research on the Base64 algorithm is very useful. A simple example is: batch processing encryption, binary files embedded in bat, processing EMail, etc.
Last edited by electronixtar on 2006-11-15 at 01:25 AM ]
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-13 13:07 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
我先提一个思路,用 fc 命令获得文件流的每一个字节的ASCII码。(其实fc的很多用处被大家忽略了)。但是,用什么来把ASCII码还原成字符呢?包括一些批处理不能处理的 乱码、不可见字符 呢(ASCII码128以后的那些)?
btw,新手们,搞理论研究很枯燥,但是很有用,请你们多多支持,多多理解!其实我们联盟的某些方面的批处理技术已经是世界顶尖水准了。
Last edited by electronixtar on 2006-11-13 at 01:27 PM ]
I first put forward an idea, using the fc command to obtain the ASCII code of each byte of the file stream. (In fact, many uses of fc are ignored by everyone). But what is used to restore the ASCII code to characters? Including some garbled codes and invisible characters that batch processing cannot handle (those after ASCII code 128)?
btw, newcomers, theoretical research is boring, but very useful, please support and understand more! In fact, the batch processing technology of some aspects of our alliance is already at the world - top level.
Last edited by electronixtar on 2006-11-13 at 01:27 PM ]
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-13 13:23 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
electronixtar这个思路非常好, 相信理解这个概念并掌握他以后会有很大用途.
The idea of electronixtar is very good. I believe that after understanding this concept and mastering it, it will have great uses.
|
|
2006-11-15 00:23 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
原来没人感兴趣~~~哇啦哇啦哇啦伤心啦
So no one is interested originally~~~Wala wala wala sad啦
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-15 01:12 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
   『第 5 楼』:
使用 LLM 解释/回答一下
再贴一个世界顶尖级牛人 Herbert Kleebauer 写的 base64.cmd
@echo off
setlocal enabledelayedexpansion
set infile=a.txt
:: set infile=%1
for %%i in (%infile%) do set outfile=%%~ni.b64
echo --->%outfile%
echo Content-Type: application/octet-stream; name="%infile%">>%outfile%
echo Content-Transfer-Encoding: base64>>%outfile%
echo Content-Disposition: inline; filename="%infile%">>%outfile%
echo.>>%outfile%
set t=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
for %%i in (%infile%) do set n=%%~zi
if == goto :eof
set /p=<nul>_.a
set /p=<nul>_.b
set /p=a<nul>_.a1
set /p=b<nul>_.b1
set m=1
set /a i=-2
:loop
set /a k="%m%&%n%"
if not == copy /b _.a + _.a1>nul
if not == copy /b _.b + _.b1>nul
set /a k="%i%&%n%"
if == goto :exit
type _.a1>>_.a1
type _.b1>>_.b1
set /a m=m*2
set /a i=i*2
goto :loop
:exit
fc /b %infile% _.a|find ":">_.a1
fc /b %infile% _.b|find ":">>_.a1
sort _.a1>_.b1
set n=
set m=0
set k=0
set q=0
for /f "tokens=1,2" %%i in (_.b1) do (
if not == (
set i=%%j
call :dig !i:~0,1!
set /a m=!m!*16+!j!
call :dig !i:~1,1!
set /a m=m*16+j
set /a k=k+1
if !k!==3 (
set /a p="m>>18"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>12)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>6)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="m&63"
call set x=!x!%%t:~!p!,1%%
set /a q=q+1
if == (
echo !x!>>%outfile%
set x=
set q=0)
set m=0
set k=0))
set n=%%i)
if == (
set /a p="m>>2"
call set x=!x!%%t:~!p!,1%%
set /a p="(m<<4)&63"
call set x=!x!%%t:~!p!,1%%==)
if == (
set /a p="m>>10"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>4)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="(m<<2)&63"
call set x=!x!%%t:~!p!,1%%=)
if not == echo %x%>>%outfile%
echo.>>%outfile%
echo ----->>%outfile%
del _.a
del _.a1
del _.b
del _.b1
goto :eof
:dig
set j=%1
if == set j=10
if == set j=11
if == set j=12
if == set j=13
if == set j=14
if == set j=15
Post another world-class expert Herbert Kleebauer's written base64.cmd
@echo off
setlocal enabledelayedexpansion
set infile=a.txt
:: set infile=%1
for %%i in (%infile%) do set outfile=%%~ni.b64
echo --->%outfile%
echo Content-Type: application/octet-stream; name="%infile%">>%outfile%
echo Content-Transfer-Encoding: base64>>%outfile%
echo Content-Disposition: inline; filename="%infile%">>%outfile%
echo.>>%outfile%
set t=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
for %%i in (%infile%) do set n=%%~zi
if == goto :eof
set /p=<nul>_.a
set /p=<nul>_.b
set /p=a<nul>_.a1
set /p=b<nul>_.b1
set m=1
set /a i=-2
:loop
set /a k="%m%&%n%"
if not == copy /b _.a + _.a1>nul
if not == copy /b _.b + _.b1>nul
set /a k="%i%&%n%"
if == goto :exit
type _.a1>>_.a1
type _.b1>>_.b1
set /a m=m*2
set /a i=i*2
goto :loop
:exit
fc /b %infile% _.a|find ":">_.a1
fc /b %infile% _.b|find ":">>_.a1
sort _.a1>_.b1
set n=
set m=0
set k=0
set q=0
for /f "tokens=1,2" %%i in (_.b1) do (
if not == (
set i=%%j
call :dig !i:~0,1!
set /a m=!m!*16+!j!
call :dig !i:~1,1!
set /a m=m*16+j
set /a k=k+1
if !k!==3 (
set /a p="m>>18"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>12)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>6)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="m&63"
call set x=!x!%%t:~!p!,1%%
set /a q=q+1
if == (
echo !x!>>%outfile%
set x=
set q=0)
set m=0
set k=0))
set n=%%i)
if == (
set /a p="m>>2"
call set x=!x!%%t:~!p!,1%%
set /a p="(m<<4)&63"
call set x=!x!%%t:~!p!,1%%==)
if == (
set /a p="m>>10"
call set x=!x!%%t:~!p!,1%%
set /a p="(m>>4)&63"
call set x=!x!%%t:~!p!,1%%
set /a p="(m<<2)&63"
call set x=!x!%%t:~!p!,1%%=)
if not == echo %x%>>%outfile%
echo.>>%outfile%
echo ----->>%outfile%
del _.a
del _.a1
del _.b
del _.b1
goto :eof
:dig
set j=%1
if == set j=10
if == set j=11
if == set j=12
if == set j=13
if == set j=14
if == set j=15
此帖被 +7 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +5 | 时间:2006-11-15 02:49 | 评分人:【 0401 】 | 分数: +2 | 时间:2007-1-11 00:43 |
|
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-15 01:20 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
不是不感兴趣, 只是我这样的菜鸟功力不够, 就听你讲课, 多长点见识, 呵呵~
It's not that I'm not interested, it's just that I'm a rookie with insufficient skills. Just listening to your lecture, I can gain more insights, heh heh~
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-11-15 01:21 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
pengfei你都高会了还菜鸟~~~太谦虚了吧,至少也算老鸟~~
Pengfei, you're already very skilled but still call yourself a newbie~~~ That's too modest. At least you can be considered an old hand~
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-15 01:27 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
呵呵~ electronixtar兄过奖了, 我是真不会.
Hehe~ Brother electronixtar, you're too kind. I really don't know how.
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-11-15 01:35 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
electronixtar兄,每一行后都有一个空格,害得我以为代码有问题呢。
Brother electronixtar, there is a space after each line, which made me think there was a problem with the code.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-11-15 01:35 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
谁说没人感兴趣~~
这个帖子太好了,值得好好的研究一下~~~顶一个先~
Who says no one is interested~~
This post is great, worthy of careful study~~~First, give it a thumbs up~
|
|
2006-11-15 01:46 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
re ccwan:
我是直接复制粘贴的~~汗~~
re ccwan:
I just copied and pasted it~ ~ Sweat~ ~
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-15 04:49 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
 『第 12 楼』:
使用 LLM 解释/回答一下
转一个 Base64 简介
作者: lcother@163.net
奇妙的Base64编码
各位看官应该都是资深的网虫了,小弟斗胆在此问问大家,平时上网时,除了泡MM、到论坛灌水、扔版砖……之外,进行的最多的是什么活动?对了,你一定会说:是收发电子邮件!(谁敢说自己没收/发过电子邮件的?拉出去枪毙了!!)
收/发E-mail的时候有一个安全性的问题--假想一下,你花了一整天时间给系花写的情书,在发送的过程中被隔壁宿舍张三那小子截获了(难道他是黑客??),更糟的是他是你的情敌啊……天,后果不堪设想!!因此,我们必须有一种比较可靠的加密方法,能够对电子邮件的明文进行转换,至少要得出一个无法被别人一眼就看出内容来的东西,而且编码/解码的速度还要足够快。(这时你可以再假想一下啦,张三那家伙截获了你的肉麻情书,可是他一看:“咦?怎么乱七八糟的?垃圾邮件!!”--这样一来你不就逃过大难了?!)
Base64就是在这种背景下产生的加密方法。它的特点是:1、速度非常快。2、能够将字符串A转换成字符串B,而且如果你光看字符串B,是绝对猜不出字符串A的内容来的。不信吗?让我们来看看下面这串东西:
xOO6w6Osu7bTrbniwdnAz8LetcTnzbfXzOy12KOh
呵呵,是什么啊?猜出来了吗?其实它就是下面这段文字经过Base64编码产生的东东:
你好,欢迎光临老罗的缤纷天地!
介绍说完啦,让我们开始探讨实质性的东西。
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045~RFC2049,上面有MIME的详细规范。
Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3。
这样说会不会太抽象了?不怕,我们来看一个例子:
转换前 aaaaaabb ccccdddd eeffffff
转换后 00aaaaaa 00bbcccc 00ddddee 00ffffff
应该很清楚了吧?上面的三个字节是原文,下面的四个字节是转换后的Base64编码,其前两位均为0。
转换后,我们用一个码表来得到我们想要的字符串(也就是最终的Base64编码),这个表是这样的:(摘自RFC2045)
Table 1: The Base64 Alphabet
value Encoding value Encoding value Encoding value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
让我们再来看一个实际的例子,加深印象!
转换前 10101101 10111010 01110110
转换后 00101011 00011011 00101001 00110110
十进制 43 27 42 54
对应码表中的值 r b q 2
所以上面的24位编码,编码后的Base64值为 rbq2
解码同理,把 rbq2 的二进制位连接上再重组得到三个8位值,得出原码。
(解码只是编码的逆过程,在此我就不多说了,另外有关MIME的RFC还是有很多的,如果需要详细情况请自行查找。)
用更接近于编程的思维来说,编码的过程是这样的:
第一个字符通过右移2位获得第一个目标字符的Base64表位置,根据这个数值取到表上相应的字符,就是第一个目标字符。
然后将第一个字符左移6位加上第二个字符右移4位,即获得第二个目标字符。
再将第二个字符左移4位加上第三个字符右移6位,获得第三个目标字符。
最后取第三个字符的右6位即获得第四个目标字符.
So easy! That’s all!!!
可是等等……聪明的你可能会问到,原文的字节数量应该是3的倍数啊,如果这个条件不能满足的话,那该怎么办呢?
我们的解决办法是这样的:原文的字节不够的地方可以用全0来补足,转换时Base64编码用=号来代替。这就是为什么有些Base64编码会以一个或两个等号结束的原因,但等号最多只有两个。因为:
余数 = 原文字节数 MOD 3
所以余数任何情况下都只可能是0,1,2这三个数中的一个。如果余数是0的话,就表示原文字节数正好是3的倍数(最理想的情况啦)。如果是1的话,为了让Base64编码是4的倍数,就要补2个等号;同理,如果是2的话,就要补1个等号。
讲到这里,大伙儿应该全明白了吧?如果还有不清楚的话就返回去再仔细看看,其实不难理解的。
An Introduction to Base64
Author: lcother@163.net
Wonderful Base64 Encoding
Dear readers, you should all be experienced netizens. I dare to ask you here, besides chatting up girls, posting on forums, and throwing bricks... what activity do you do the most? Right, you must say: it's sending and receiving emails! (Who dares to say they haven't sent/received an email? Shoot them!)
There is a security issue when sending/receiving emails - imagine that the love letter you spent all day writing to the school beauty was intercepted by that kid Zhang San from the next dormitory (Could he be a hacker??) Worse still, he's your rival in love... Oh, the consequences are unimaginable! Therefore, we must have a relatively reliable encryption method that can convert the plaintext of the email, at least to get something that can't be seen through at a glance, and the encoding/decoding speed should be fast enough. (At this time, you can imagine again that Zhang San intercepted your mushy love letter, but he saw: "Hey? Why is it all jumbled? Junk mail!!" - Then you can escape the disaster!)
Base64 is an encryption method generated under this background. Its characteristics are: 1. Very fast speed. 2. Can convert string A into string B, and if you just look at string B, you can absolutely not guess the content of string A. Don't believe it? Let's take a look at the following string:
xOO6w6Osu7bTrbniwdnAz8LetcTnzbfXzOy12KOh
Hehe, what is it? Did you guess it? Actually, it's the thing generated by Base64 encoding the following text:
Hello, welcome to Lao Luo's colorful world!
The introduction is over, let's start to explore the substantive things.
Base64 is one of the most common encoding methods used to transmit 8-bit byte codes on the network. You can check RFC2045 ~ RFC2049, where there are detailed specifications of MIME.
Base64 requires converting every three 8-bit bytes into four 6-bit bytes (3*8 = 4*6 = 24), and then adding two high bits 0 to the 6 bits to form four 8-bit bytes, that is to say, the converted string will theoretically be 1/3 longer than the original.
Will this be too abstract? Don't worry, let's look at an example:
Before conversion aaaaaabb ccccdddd eeffffff
After conversion 00aaaaaa 00bbcccc 00ddddee 00ffffff
It should be very clear, right? The above three bytes are the original text, and the following four bytes are the converted Base64 encoding, and their first two bits are both 0.
After conversion, we use a code table to get the string we want (that is, the final Base64 encoding). This table is as follows: (excerpted from RFC2045)
Table 1: The Base64 Alphabet
value Encoding value Encoding value Encoding value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 60 8
9 J 26 a 43 r 61 9
10 K 27 b 44 s 62 +
11 L 28 c 45 t 63 /
12 M 29 d 46 u (pad) =
13 N 30 e 47 v
14 O 31 f 48 w
15 P 32 g 49 x
16 Q 33 h 50 y
Let's look at a practical example to deepen the impression!
Before conversion 10101101 10111010 01110110
After conversion 00101011 00011011 00101001 00110110
Decimal 43 27 42 54
Corresponding values in the code table r b q 2
So the above 24-bit encoding, the encoded Base64 value is rbq2
Decoding is the same, connect the binary bits of rbq2 and then reorganize to get three 8-bit values, and get the original code.
(Decoding is just the reverse process of encoding, so I won't say more here. In addition, there are many RFCs about MIME. If you need detailed information, please find it yourself.)
In a more programming-like way of thinking, the encoding process is as follows:
The first character gets the position of the first target character in the Base64 table by shifting right by 2 bits, and takes the corresponding character on the table according to this value, which is the first target character.
Then shift the first character left by 6 bits and add the second character shifted right by 4 bits to get the second target character.
Then shift the second character left by 4 bits and add the third character shifted right by 6 bits to get the third target character.
Finally, take the right 6 bits of the third character to get the fourth target character.
So easy! That’s all!!!
But wait... The clever you may ask, the number of bytes of the original text should be a multiple of 3. What if this condition is not met?
Our solution is like this: the place where the bytes of the original text are not enough can be filled with all 0s, and the Base64 encoding uses = signs instead. This is why some Base64 encodings end with one or two equal signs, but there are at most two equal signs. Because:
Remainder = original text byte number MOD 3
So the remainder can only be one of 0, 1, 2 in any case. If the remainder is 0, it means that the number of original text bytes is exactly a multiple of 3 (the most ideal situation). If it is 1, in order to make the Base64 encoding a multiple of 4, 2 equal signs need to be added; similarly, if it is 2, 1 equal sign needs to be added.
By this time, everyone should understand it all. If there is still any ambiguity, go back and read it carefully. Actually, it's not difficult to understand.
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-18 01:29 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
好东西。泡妞密文。
Good stuff. Pick-up lines.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-11-18 01:43 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
欣赏~~
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-18 02:06 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
我还是没有看到具体怎么“加密”
I still haven't seen exactly how to "encrypt"
|
|
2006-11-18 02:25 |
|
|