Answer the question
In order to leave comments, you need to log in
RC4 why not complete result?
In general, I'm trying to transfer js code to delphi, but when checking, it gives a cut in delphi, not all text is encrypted here
js
function rc4(key, str) {
/* jshint bitwise: false */
var s = [], j = 0, x, res = '';
for (var i = 0; i < 256; i++) {
s[i] = i;
}
for (i = 0; i < 256; i++) {
j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
x = s[i];
s[i] = s[j];
s[j] = x;
}
i = 0;
j = 0;
for (var y = 0; y < str.length; y++) {
i = (i + 1) % 256;
j = (j + s[i]) % 256;
x = s[i];
s[i] = s[j];
s[j] = x;
res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
}
return res;
}
function RC4Encrypt(key, Text: String): String;
var
i, j, X, Y: Integer;
s: array [0 .. 255] of Integer;
charCode: Integer;
ct: String;
ctInt: Integer;
begin
for i := 0 to 255 do
begin
s[i] := i;
end;
j := 0;
for i := 0 to 255 do
begin
charCode := Ord(char(key[(i MOD Length(key)) + 1]));
j := (j + s[i] + charCode) MOD 256;
X := s[i];
s[i] := s[j];
s[j] := X;
end;
i := 0;
j := 0;
ct := '';
for Y := 0 to (Length(Text) - 1) do
begin
i := (i + 1) MOD 256;
j := (j + s[i]) MOD 256;
X := s[i];
s[i] := s[j];
s[j] := X;
ctInt := Ord(char(Text[Y + 1])) xor (s[((s[i] + s[j]) MOD 256)]);
ct := concat(ct, String(Chr(ctInt)));
end;
Result := ct;
end;
1 значение delphi
8M¨=ÎJ¾2páS
ËÁÛ+<TÐWPÒµ Â\;TYcEÅ)PÙ uø¥Ö#zÙëí|®iuw)0ø<E~£ëp_øíõT\¥¡í0cÆ£uúÓÝ;!TýeHÙ¥W2,W©xNñ
¯+ðD\ØÈ"óN-?ÜS6]àÝb~( ÁeIq
2 значение js
8M¨=ÎJ\u001d¾2\fpáS\nËÁÛ+<TÐWPÒ\u001aµ\u0018 \u0019Â\\;T\u001eYcEÅ)PÙ\tuø\u001b\u001a\u001f¥\u001cÖ#zÙë\fí\u001f\u001f|®iu\u0002w)0ø<E~£\bë\u0011\u000e\u0001p_øíõT\\¥\u0007¡í0cÆ£uúÓÝ;!T\u000fýeHÙ¥W2,W©xNñ\u000b\r¯+ðD\\ØÈ\"óN-\u0019?ÜS6]àÝb~( ÁeIq\u0000O\u001a±®`¢Ú¹\u0004\ftzÒýEÖÿ\[email protected]\u000eåÚ>óòz.ý¨\naG(ËÓgPRÔΨKÙ\u001e$a¢7C[\u000e\u0014³ ÿ4bÇ8ó´ì=ζoS^Ûj\u0004ý5\n¿]\u001bJNêa}~`r×ë\u0014´(·Ôék`\u0013ÙôB¨þ_îr\u0018Íí§uÆ\u0011ß\u0005fzãÒ\u0011²0X.\u001eÂ\tÿ\u0005ËFMYØLó]ä=\u001d99îØöA\u00164׿Xv\u0007c%ôk]Îw¦Ri\u0011ø\u0013K}B.]ycйZ\u0005±ëçR]dò!&hà1¡\u0003ÐÐ%Èù\u001a²®øücè.Õh¿ÞÅáFÉ©ûdC®i\u0012\tHpò1Ûâ*u[:«\u0004íA×®\u001b+Ðô>±qª3ÔÓÇ[¯=rD°Õöó©óÈB£+J¾#}QTÁÍDP}¯È\u0005+ÞPJ±¸\bSîC¦®ÔU³à\u0010\u000eôEH¶N\u0018÷b\bô´£ \rJ¡C -Ö\b\u0002ªâJþ`^#\tÇÛ$/GºÚ\\Ý\u000bOòµ<$\"7hµßø{êÞÆ[email protected]\tÕÓ°\"ª¢\u0012Z7FßC±7ø¨`l8\u001dF\u001aÕðÏj\u0000A!°\u000bËNvÃ\u0003E}÷\u0006Â}Ýa\u0019¼?d£\u0010\u0000í`P0ËExzÖ¦C\\ã¸èÜKmâVâ¹=]Á«\u001fÖ\tíc5T½?ûirnô´]:rûÌÛ/º÷RiÑÄù,f÷f7ÓåFÎcð\u0011ºÀiëÊ\u0010´8µUÎæÊ\u001a&@{Øßé¢Æ)=\u001eªÑѳy\b\u0011òd([ »q*¨ï×É\u0017\u0014\b\u0010R>f\u001eÎö#âhE³eMÀlS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HCuAhTw67Ck0PCgsKmwq7DlFXCs8OgEA7DtEVIwrZOGMO3YgjDtMOCwrTCoyANSsKhQyAtw5YIAsKBwqrDokrDvmBeIwnDh8ObwoIkL0fCjcK6woLDmlzDnQtPw7LCtTzCkSQiN2jCtcOfw7h7w6rDnsOGTkBjCcOVw5PCsCLCqsKiElo3RsOfQ8KxN8O4wqhgbDjCix1GwpQaf8OVw7DDj2oAQSHCsMKaC8OLTnbCm8ODA8KeRX3Dt8KZBsOCfcOdYRnCvD9kwqMQwoIAwpbCh8OtwpdgUDDDi0V4esOWwqZDXMKWwpTDo8K4w6jDnEttw6JWw6LCuT1dw4HCqx/DlgnDrWM1VMK9wpQ/woXDu2nCgXJuw7TCtMKIXTrClMKfcsO7w4zDmy/CjsK6w7fCnFJpw5HDhMO5LGbDt2Y3wp7Dk8OlRsOOY8OwEcK6w4Bpw6vDihDCtDjCtVXDjsOmworCkMOKwooaJkB7w5jDn8OpwqLDhik9HsKLwo/CqsORw5HCs3kIEcOyZChbIMK7cSrCqMOvw5fDicKAwpIXFAgQUsKQPmYew47DtiPDomhFwrNlwo5NwprDgGxTDMOmAn4nw40Zw4RGw41Vw7VNAV7DpBlhw4Myw7zConhjPmtgAU4QE8OROMKdw6PCmcOqw73CtRrCqMOGwoPCjcKhw4ULw4kyPDQBPMKJw5hGMcOH"
delphi значение, видно, что правильно кодирует, но почему не весь текст?
OE3ClcKowpU9wobDjkrCgB1/wr4yDHDDoVMKwozDi8OBw5vCnys8VMOQV1DDkhrCtRjCj8KgGcKdw4JcO1QeWWNFw4XCmylQw5kJdcO4wpUbGh/CisKlHH/DliN6w5nDqwzDrcKYHx98wq5pdQJ3KTDDuDxFfsKjCMOrEQ7CjAFwwphfwp/DuMOtw7VUwo5cwqUHwqHCk8OtMGPClMOGwqPClHXDusOTw507IcKPwpBUD8O9wpVlSMOZwqVXMixXwql4TsKPwoHDscKPCw3CryvDsERcwofDmMOIwoIiw7NOLRk/w5xTNl3Cl8KJw6DDnWJ+KMKgw4FlSXE=
Answer the question
In order to leave comments, you need to log in
Instead of Chr, which returns it is not clear what, Char is needed for the analogy. Or is it what version of Delphi? In the old ones (2007 and older), for analogy, this is WideChar.
Looked, and on what the Delphi version is interrupted. In JavaScript, this is \u0000. One might think that Delphi worked as it should, and the problem is in the display system, which is encoded in an outdated programming language with an outdated string length encoding system with a null character embedded at the end of the string. Change the piece where it is being cut, and the line will be preserved in its entirety.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question