[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

【出题】批处理实现16进制数据最小体积存储

  1. 4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000E00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000484CF28A0C2D9CD90C2D9CD90C2D9CD90C2D9CD90F2D9CD9633296D9072D9CD98F3192D90D2D9CD9633298D90F2D9CD90C2D9DD91C2D9CD93A0B96D90D2D9CD9526963680C2D9CD9000000000000000000000000000000000000000000000000504500004C0103002B63CA4D0000000000000000E0000F010B0106009001000030020000000000008E02000050020000E003000000004000100000001000000004000000000000000400000000000000100600005002000000000000030000000000100000100000000010000010000000000000100000000000000000000000340400003C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E0030000440000000000000000000000000000000000000000000000000000002E7465787400000082010000500200009001000050020000000000000000000000000000200000602E72646174610000CA010000E0030000D0010000E0030000000000000000000000000000400000402E646174610000005C000000B005000060000000B0050000000000000000000000000000400000C0837C2404037D0F68C4054000E827000000596A0158C38B44240833C95151FF7008FF700451E85201000068C0054000E8040000005933C0C3FF25E0034000558BEC6AFF682804400068C003400064A100000000506489250000000083EC205356578965E88365FC006A01FF150C04400059830D00064000FF830D04064000FFFF15080440008B0DFC0540008908FF15040440008B0DF80540008908A1000440008B00A308064000E8C3000000833DE005400000750C68BC034000FF15FC03400059E89400000068BC05400068B8054000E87F000000A1F40540008945D88D45D850FF35F00540008D45E0508D45D4508D45E450FF15F403400068B405400068B0054000E84C000000FF15F00340008B4DE08908FF75E0FF75D4FF75E4E8DFFEFFFF83C4308945DC50FF15EC0340008B45EC8B088B09894DD05051E80F0000005959C38B65E8FF75D0FF15E4034000FF25E8034000FF25F803400068000003006800000100E80D0000005959C333C0C3C3FF2510044000FF2514044000FF251C0440000000000000000000000000000000B4040000C8040000D0040000DE040000E6040000F6040000060500001205000026050000360500004605000054050000660500007A05000000000000880500000000000000000000FFFFFFFF7E03400092034000700400000000000000000000BC040000E0030000AC04000000000000000000009E0500001C0400000000000000000000000000000000000000000000B4040000C8040000D0040000DE040000E6040000F6040000060500001205000026050000360500004605000054050000660500007A050000000000008805000000000000A1027075747300004D53564352542E646C6C0000D3005F657869740048005F5863707446696C74657200490265786974000064005F5F705F5F5F696E6974656E760058005F5F6765746D61696E61726773000F015F696E69747465726D0083005F5F736574757365726D61746865727200009D005F61646A7573745F6664697600006A005F5F705F5F636F6D6D6F646500006F005F5F705F5F666D6F6465000081005F5F7365745F6170705F747970650000CA005F6578636570745F68616E646C6572330000B7005F636F6E74726F6C667000003E0055524C446F776E6C6F6164546F46696C6541000075726C6D6F6E2E646C6C0000000000000000000000000000000000000000000000004F4B210055736167653A20444F574E203C75726C3E203C706174683E000000000100
复制代码
设计一种编码批处理变量存放方案,将上面的字符信息用尽量少的字符个数储存,当使用的时候,又可以用相应的方案还原。
简单的理解就是类似于数据压缩与解压缩操作。

要求,用cmd的内部命令实现。
----------------------------------------
PS: 这个“设计方案”所含的批处理代码不要过长,体积的计算要把这个“设计方案”所含代码和储存信息一起计算。

当然,如果方案能通用的话,可以适当放宽设计方案所含代码的长度

本帖最后由 plp626 于 2011-5-11 23:21 编辑

PS: 这个“设计方案”所含的批处理代码不要过长,体积的计算要把这个“设计方案”所含代码和储存信息一起计算。

当然,如果方案能通用的话,可以适当放宽设计方案所含代码的长度

-----------------------------------

有人也许会问这个能干什么? 我说下应用,当然还是娱乐,但“娱乐度”比较高,呵呵。

有个霍夫曼编码,可以对所发报文以最短编码存储,我们把他应用到bat2any(利用debug写文件)那个程序里,可以最大限度的压缩文件的体积,

假如有人想把三方工具嵌入到bat中,这样体积可以压缩很多多多。。。。

TOP

如果源文件是 32 位命令行,直接使用 UPX 压缩
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

3# hanyeguxing


上面这个exe文件体积就1K多,选择编译的时候我加了/align:16,体积最小模式,upx没法再压缩了

TOP

16*16 =256
一个简单的办法就是使用ACSII码。

DEBUG即可互相转换。

TOP

同上,相信大家第一反映都差不多,不过我想,无论用ansi码或者什么码来以字典的形式与原始数据一一对应,其根本思路无非是把16进制转换为更高位的进制,以填补用1~2个字节只记录一个十六进制数时浪费的容量。
对于调用第三方、debug、vbs等方法不做评论,因为想必都是可行的,不过我想楼主的意思大概是尽量用纯批的吧。
再说一个大众看法,大家肯定都想到了,只是没说。首先,字典肯定要用到的,再用A个字典里的字符与B个十六进制数对应,不过要知道A:B的最佳比例,就要做一个计算:将能在批处理中识别为单字符的单字节ansi码数量设为N,然后求N与16的最小公倍数,然后...你知道的,不解释

TOP

转 Base64码

TOP

楼主提供的本身就是源文件的 ANSI 。。。
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

转 Base64码 后文件原来的 2/3

TOP

我看0出现很多次,要不用N个0表示  恩恩
1

评分人数

TOP

我目前,理论上,

可以把一楼的数据压缩到1100 字节左右(不含解压代码)

也就是压缩为原来体积的37%左右。

不知大家的结果是怎样的?

TOP

如果引入有损压缩的概念,压缩比必定更高

TOP

本帖最后由 batman 于 2011-5-13 00:57 编辑

思路:
0-9的数字就用原值存储(原来用两个字符存储压缩一半),a-z和A-Z全用a-z表示(压缩比视大小写字母比),非数值非字母可见字符用原值存储(原来用两个字符存储压缩一半,),回车换行退格分别用A、B、C存储(压缩一半)。
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "skip=8 tokens=1*" %%a in (%~fs0) do set "%%a=%%b"
  3. set "str=4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000E00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000484CF28A0C2D9CD90C2D9CD90C2D9CD90C2D9CD90F2D9CD9633296D9072D9CD98F3192D90D2D9CD9633298D90F2D9CD90C2D9DD91C2D9CD93A0B96D90D2D9CD9526963680C2D9CD9000000000000000000000000000000000000000000000000504500004C0103002B63CA4D0000000000000000E0000F010B0106009001000030020000000000008E02000050020000E003000000004000100000001000000004000000000000000400000000000000100600005002000000000000030000000000100000100000000010000010000000000000100000000000000000000000340400003C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E0030000440000000000000000000000000000000000000000000000000000002E7465787400000082010000500200009001000050020000000000000000000000000000200000602E72646174610000CA010000E0030000D0010000E0030000000000000000000000000000400000402E646174610000005C000000B005000060000000B0050000000000000000000000000000400000C0837C2404037D0F68C4054000E827000000596A0158C38B44240833C95151FF7008FF700451E85201000068C0054000E8040000005933C0C3FF25E0034000558BEC6AFF682804400068C003400064A100000000506489250000000083EC205356578965E88365FC006A01FF150C04400059830D00064000FF830D04064000FFFF15080440008B0DFC0540008908FF15040440008B0DF80540008908A1000440008B00A308064000E8C3000000833DE005400000750C68BC034000FF15FC03400059E89400000068BC05400068B8054000E87F000000A1F40540008945D88D45D850FF35F00540008D45E0508D45D4508D45E450FF15F403400068B405400068B0054000E84C000000FF15F00340008B4DE08908FF75E0FF75D4FF75E4E8DFFEFFFF83C4308945DC50FF15EC0340008B45EC8B088B09894DD05051E80F0000005959C38B65E8FF75D0FF15E4034000FF25E8034000FF25F803400068000003006800000100E80D0000005959C333C0C3C3FF2510044000FF2514044000FF251C0440000000000000000000000000000000B4040000C8040000D0040000DE040000E6040000F6040000060500001205000026050000360500004605000054050000660500007A05000000000000880500000000000000000000FFFFFFFF7E03400092034000700400000000000000000000BC040000E0030000AC04000000000000000000009E0500001C0400000000000000000000000000000000000000000000B4040000C8040000D0040000DE040000E6040000F6040000060500001205000026050000360500004605000054050000660500007A050000000000008805000000000000A1027075747300004D53564352542E646C6C0000D3005F657869740048005F5863707446696C74657200490265786974000064005F5F705F5F5F696E6974656E760058005F5F6765746D61696E61726773000F015F696E69747465726D0083005F5F736574757365726D61746865727200009D005F61646A7573745F6664697600006A005F5F705F5F636F6D6D6F646500006F005F5F705F5F666D6F6465000081005F5F7365745F6170705F747970650000CA005F6578636570745F68616E646C6572330000B7005F636F6E74726F6C667000003E0055524C446F776E6C6F6164546F46696C6541000075726C6D6F6E2E646C6C0000000000000000000000000000000000000000000000004F4B210055736167653A20444F574E203C75726C3E203C706174683E000000000100"
  4. :lp
  5. set "var=!var!!%str:~,2%!"
  6. if defined str set "str=%str:~2%"&goto lp
  7. set "var=!var:空格= !"
  8. echo !var:跳格= !
  9. pause>nul&goto :eof
  10. 09 跳格
  11. 20 空格
  12. 21 !
  13. 22 "
  14. 23 #
  15. 24 $
  16. 25 %
  17. 26 &
  18. 27 '
  19. 28 (
  20. 29 )
  21. 2A *
  22. 2B +
  23. 2C ,
  24. 2D -
  25. 2E .
  26. 2F /
  27. 30 0
  28. 31 1
  29. 32 2
  30. 33 3
  31. 34 4
  32. 35 5
  33. 36 6
  34. 37 7
  35. 38 8
  36. 39 9
  37. 3A :
  38. 3B ;
  39. 3C <
  40. 3D =
  41. 3E >
  42. 3F ?
  43. 40 @
  44. 41 a
  45. 42 b
  46. 43 C
  47. 44 d
  48. 45 e
  49. 46 f
  50. 47 g
  51. 48 h
  52. 49 i
  53. 4A j
  54. 4B k
  55. 4C l
  56. 4D m
  57. 4E n
  58. 4F o
  59. 50 p
  60. 51 q
  61. 52 r
  62. 53 s
  63. 54 t
  64. 55 u
  65. 56 v
  66. 57 w
  67. 58 x
  68. 59 y
  69. 5A z
  70. 5B [
  71. 5C \
  72. 5D ]
  73. 5E ^
  74. 5F _
  75. 60 `
  76. 61 a
  77. 62 b
  78. 63 c
  79. 64 d
  80. 65 e
  81. 66 f
  82. 67 g
  83. 68 h
  84. 69 i
  85. 6A j
  86. 6B k
  87. 6C l
  88. 6D m
  89. 6E n
  90. 6F o
  91. 70 p
  92. 71 q
  93. 72 r
  94. 73 s
  95. 74 t
  96. 75 u
  97. 76 v
  98. 77 w
  99. 78 x
  100. 79 y
  101. 7A z
  102. 7B {
  103. 7C |
  104. 7D }
  105. 7E ~
  106. 0A A
  107. 0D B
  108. 08 C
复制代码
1

评分人数

***共同提高***

TOP

11# plp626


用批处理自身来存储、解压,怎么能不算解压代码呢?
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

另一思路  把一定长度字符(转为10进制) 除一固定数 储存这个信息

TOP

返回列表