找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 6087|回复: 5

[其他] 怎么用unicode隐藏字符制作Token炸弹

[复制链接]
发表于 2025-5-30 15:11:26 | 显示全部楼层 |阅读模式
https://newsa.html5.qq.com/v1/share-article?ch=009405&data_type=1&docId=5074705696591219010&from_app=qb&sGuid=52ba6464e980b2329545aaf20bc588cb&sQueryId=1741686064051&sUserId=&sUserType=&sh_sid=5____&target_app=kb


这个网址里,有一个特殊字符,在     复制到OpenAI的那个测有多少token的网站里,来看看这个n藏了多少token。


这一行,这个n复制后有15k大小,怎么编码的?
发表于 2025-5-31 00:50:40 | 显示全部楼层
大概就是一些没有码点跟字形的字符叠在一起 ,因为没有码点跟字形 ,当然也就不显示了 ,也因为不显示 ,字符宽度相当于0 ,选择时的判断就自然全选上了
要弄的话直接找unicode没有使用的区域就行 ,unicode的第4至13辅助平面貌似就尚未使用
 楼主| 发表于 2025-5-31 07:01:34 | 显示全部楼层
他的是可以编码解码的,把一篇文章编进去,再解码出来
我也用winhex看了,但看不出怎么进行编码和解码
发表于 2025-5-31 09:51:23 | 显示全部楼层
那应该是作者自己设计的编码表 ,貌似不是单纯的运算转换
字符A-Z是从U+e0110开始的26个
字符a-z是从U+e0151开始的26个
空格是U+e0110
换行是U+fe0a
....
其实不一定要按照那里的作者那样 ,也可以自己设计编码表或转换方式 ,只要找到并利用那些的不显示的字符就行了
例如下面的 ,保存为utf8编码的html ,然后用支持es6标准的浏览器打开
(U+e0000至U+e00ff好像是不显示的 ,通过直接将字符看成单字节然后加上0xe0000来实现的)

  1. <!DOCTYPE html>
  2. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  3. <head><script type="text/javascript" >
  4. function the_nil_coding(){
  5. this.chr=[];
  6. for(var i=0xe0000;i<=0xe00ff;i++){
  7. this.chr.push(String.fromCodePoint(i));
  8. }

  9. this.encode=function(str,pre){
  10. var rt=[];
  11. if(pre){
  12. rt.push(pre);
  13. }else{
  14. rt.push('N');
  15. }
  16. rt.push(String.fromCodePoint(0xe0100));
  17. if(!str||!str.length)return rt.join('');
  18. var c=str.length;
  19. for(var i=0;i<c;i++){
  20. var p=str.charCodeAt(i);
  21. var h=p>>>8;
  22. var l=p&0xff;
  23. rt.push(this.chr[h]);
  24. rt.push(this.chr[l]);
  25. }
  26. return rt.join('');
  27. }

  28. this.decode=function(str){
  29. var k=0,j=0,rt=[];
  30. if(!str||!str.length)return rt.join('');
  31. for(let i of str){
  32. var p=i.codePointAt(0);
  33. if(p==0xe0100)k=1;
  34. if(k){
  35. if(p>=0xe0000&&p<0xe0100){
  36. j++;
  37. if(j==2){
  38. var l=p-0xe0000;
  39. rt.push(String.fromCharCode(h+l));
  40. h=0,l=0,j=0;
  41. }else{
  42. var h=(p-0xe0000)<<8;
  43. }
  44. }}}
  45. return rt.join('');
  46. }
  47. }

  48. window.onload=function(){
  49. var nil_coding=new the_nil_coding();
  50. document.getElementById('ec').onclick=function(){
  51. document.getElementById('rs').value='';
  52. var t=nil_coding.encode(
  53. document.getElementById('ip').value,document.getElementById('pf').value);
  54. document.getElementById('rs').value=t;};
  55. document.getElementById('dc').onclick=function(){
  56. document.getElementById('rs').value='';
  57. var t=nil_coding.decode(document.getElementById('ip').value);
  58. document.getElementById('rs').value=t;}
  59. document.getElementById('cli').onclick=function(){
  60. document.getElementById('ip').value='';}
  61. document.getElementById('clr').onclick=function(){
  62. document.getElementById('rs').value='';}
  63. document.getElementById('cla').onclick=function(){
  64. document.getElementById('ip').value='';
  65. document.getElementById('rs').value='';}
  66. }
  67. </script></head>
  68. <body>
  69. <label>input</label><input id='cli' type='button' value='clear'/></br>
  70. <textarea id='ip' style="width:450px;height:200px;border:2px solid;"></textarea></br></br>
  71. <label>prefix:</label><input id='pf' type="text" value="N"/>
  72. <input id='ec' type='button' value='encode input'/>
  73. <input id='dc' type='button' value='decode input'/>
  74. <input id='cla' type='button' value='clear all'/>
  75. </br></br>
  76. <textarea id='rs' style="width:450px;height:200px;border:2px solid;"></textarea></br>
  77. <label>result</label><input id='clr' type='button' value='clear'/></br>
  78. </body></html>
复制代码
发表于 2025-6-1 01:15:24 | 显示全部楼层
搜了下 ,github有对应项目
https://github.com/paulgb/emoji-encoder
下面是ts源码

  1. // Variation selectors block https://unicode.org/charts/nameslist/n_FE00.html
  2. // VS1..=VS16
  3. const VARIATION_SELECTOR_START = 0xfe00;
  4. const VARIATION_SELECTOR_END = 0xfe0f;

  5. // Variation selectors supplement https://unicode.org/charts/nameslist/n_E0100.html
  6. // VS17..=VS256
  7. const VARIATION_SELECTOR_SUPPLEMENT_START = 0xe0100;
  8. const VARIATION_SELECTOR_SUPPLEMENT_END = 0xe01ef;

  9. export function toVariationSelector(byte: number): string | null {
  10.     if (byte >= 0 && byte < 16) {
  11.         return String.fromCodePoint(VARIATION_SELECTOR_START + byte)
  12.     } else if (byte >= 16 && byte < 256) {
  13.         return String.fromCodePoint(VARIATION_SELECTOR_SUPPLEMENT_START + byte - 16)
  14.     } else {
  15.         return null
  16.     }
  17. }

  18. export function fromVariationSelector(codePoint: number): number | null {
  19.     if (codePoint >= VARIATION_SELECTOR_START && codePoint <= VARIATION_SELECTOR_END) {
  20.         return codePoint - VARIATION_SELECTOR_START
  21.     } else if (codePoint >= VARIATION_SELECTOR_SUPPLEMENT_START && codePoint <= VARIATION_SELECTOR_SUPPLEMENT_END) {
  22.         return codePoint - VARIATION_SELECTOR_SUPPLEMENT_START + 16
  23.     } else {
  24.         return null
  25.     }
  26. }

  27. export function encode(emoji: string, text: string): string {
  28.     // convert the string to utf-8 bytes
  29.     const bytes = new TextEncoder().encode(text)
  30.     let encoded = emoji

  31.     for (const byte of bytes) {
  32.         encoded += toVariationSelector(byte)
  33.     }

  34.     return encoded
  35. }

  36. export function decode(text: string): string {
  37.     let decoded = []
  38.     const chars = Array.from(text)

  39.     for (const char of chars) {
  40.         const byte = fromVariationSelector(char.codePointAt(0)!)

  41.         if (byte === null && decoded.length > 0) {
  42.             break
  43.         } else if (byte === null) {
  44.             continue
  45.         }

  46.         decoded.push(byte)
  47.     }

  48.     let decodedArray = new Uint8Array(decoded)
  49.     return new TextDecoder().decode(decodedArray)
  50. }
复制代码

评分

参与人数 1技术 +1 收起 理由
czjt1234 + 1 乐于助人

查看全部评分

 楼主| 发表于 2025-6-1 09:07:17 | 显示全部楼层
非常感谢,我慢慢看
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 05:58 , Processed in 0.018803 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表