是否有一个 Unicode 字符的作用类似于退格键或者是不可见的?

发布于 2025-01-17 13:33:20 字数 1527 浏览 4 评论 0原文

我弄乱了一系列随机的Unicode字符。我生成了两个不同长度相同的不同字符串。它们都在0到255之间的随机Unicode字符填充。我注意到程序后一个字符串的长度与另一个字符串的长度不同。剂量有人知道在Unicode中是否有一个看不见的角色或角色删除该字符?

//coded in javascript but the native language is Java
function generate(text) {
  //create an decode key array
  let decodeKey = [];
  for (let i = 0; i < text.length * 2; i++) {
    decodeKey.push(Math.floor(Math.random() * 10));
  }
  let binary = [];
  for (let i = 0; i < text.length; i++) {
    //turn text to binary and split at every 4th character
    let b = text.charCodeAt(i).toString(2);
    while (b.length < 8) {
      b = "0" + b;
    }
    binary.push(b.slice(0, 4));
    binary.push(b.slice(3));
  }
  //convert binary to a number and multiply by the decode key
  let nums = [];
  for (let i = 0; i < binary.length; i++) {
    nums.push(parseInt(binary[i].toString(10)) * decodeKey[i]);
  }
  //convert nums to unicode
  let uniChars = [];
  for (let i = 0; i < nums.length; i++) {
    uniChars.push(String.fromCharCode(parseInt(nums[i])));
  }
  //create final string with decode key at the bottom
  let result = "";
  for (let i = 0; i < uniChars.length; i++) {
    result += uniChars[i];
  }
  result += "\n"
  for (let i = 0; i < decodeKey.length; i++) {
    result += String.fromCharCode(decodeKey[i]);
  }
  //return the result
  return result;
}

console.log(generate("Test / Sample Text, Test / Sample Text, Test / Sample Text, Test / Sample Text"));

I was messing around with strings of random Unicode characters. I generated two different string that both had the same length. They were both populated with random Unicode characters between 0 and 255. I noticed after I ran the program the length of one string was different than the other. Dose anyone know if there is an invisible character or character that deletes there character before it in Unicode?

//coded in javascript but the native language is Java
function generate(text) {
  //create an decode key array
  let decodeKey = [];
  for (let i = 0; i < text.length * 2; i++) {
    decodeKey.push(Math.floor(Math.random() * 10));
  }
  let binary = [];
  for (let i = 0; i < text.length; i++) {
    //turn text to binary and split at every 4th character
    let b = text.charCodeAt(i).toString(2);
    while (b.length < 8) {
      b = "0" + b;
    }
    binary.push(b.slice(0, 4));
    binary.push(b.slice(3));
  }
  //convert binary to a number and multiply by the decode key
  let nums = [];
  for (let i = 0; i < binary.length; i++) {
    nums.push(parseInt(binary[i].toString(10)) * decodeKey[i]);
  }
  //convert nums to unicode
  let uniChars = [];
  for (let i = 0; i < nums.length; i++) {
    uniChars.push(String.fromCharCode(parseInt(nums[i])));
  }
  //create final string with decode key at the bottom
  let result = "";
  for (let i = 0; i < uniChars.length; i++) {
    result += uniChars[i];
  }
  result += "\n"
  for (let i = 0; i < decodeKey.length; i++) {
    result += String.fromCharCode(decodeKey[i]);
  }
  //return the result
  return result;
}

console.log(generate("Test / Sample Text, Test / Sample Text, Test / Sample Text, Test / Sample Text"));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文