Китайские слова становятся беспорядком в проводнике - PullRequest
0 голосов
/ 18 марта 2020

Я хочу показать что-то на сайте, введя пароль, но когда пришли китайские слова, это стало беспорядком.

function hex2int(a){
    if("0"<=a&&a<="9")return a[0].charCodeAt()-48;
    else return a[0].charCodeAt()-55;
}
function crypt(key){
    const ciphertext="D58A9ED7A4B43C3852535157545454"; // encrypt from utf-8, by Lazarus
    const len=ciphertext.length,len2=key.length;
    var cipher2="";
    for(var i=0;i<len/2;i++)
        cipher2+=String.fromCharCode((hex2int(ciphertext[i*2])*16+hex2int(ciphertext[i*2+1]))^(key[i%len2]).charCodeAt());
    return cipher2;
}
function check(){
    var psw=document.getElementById("psw").value;
    if(md5("2020S1S1S"+psw)=="f514e934ca90eac781519284406d80f7"){  // password(psw) is 123
        document.getElementById("main").innerHTML=crypt(psw); // this became a mess
        document.getElementById("verify").innerHTML=""; // 'main' and 'verify' are "div"
    }else alert("Password Wrong.\n\rAccess Denied");
}

ciphertext сделан Lazarus, код:


function crypt(const plaintext,key:ansistring):ansistring;
var
  i:longint;
begin
  crypt:='';
  for i:=1 to length(plaintext) do
    crypt:=crypt+chr(ord(plaintext[i])xor ord(key[(i-1)mod length(key)+1]));
end; 

function string2hex(a:ansistring):ansistring;
var
  ans:ansistring;
  i:longint;
  function int2hex(a:longint):char;
  begin
    if(a>=0)and(a<=9) then
      exit(chr(a+48))
    else
      exit(chr(a+55));
  end;
begin
  ans:='';
  for i:=1 to length(a) do
    ans:=ans+int2hex(ord(a[i])div 16)+int2hex(ord(a[i])mod 16);
  exit(ans);
end;               

something:=string2hex(crypt(TMemo1.Lines.Text,password));   // it is going to be the "ciphertext"                                         

код сохраняется в формате utf-8. на сайте также используется <meta charset="utf-8">

...