What is an how to use the equivalent commands (chr, xor, ord) in B4A?
B4X:
function ShuffleText(Text, Key: String): String;
var
x, y: Integer;
NewText: String;
begin
For x := 1 To Length(Key) Do
begin
NewText := '';
For y := 1 To Length(Text) Do
NewText := NewText + Chr((Ord(Key[x]) xor Ord(Text[y])));
Text := NewText;
end;
Result := Text;
end;
B4X:
Sub ShuffleText(Text As String, Key As String) As String
Dim x, y As Int
Dim NewText As String
For x := 0 To Key.Length - 1
NewText = ""
For y = 0 To Text.Length - 1
NewText = NewText + Chr((Ord(Key(x)) xor Ord(Text(y))));
Next
Text = NewText
Next
Return Text
End Sub
This is what the Delphi commands do:
The chr function converts an IntValue integer into either an AnsiChar or WideChar as appropriate.
The ord function returns an integer value for any ordinal type Arg.
The xor keyword is used to perform a logical or boolean 'Exclusive-or' of two logical values. If they are different, then the result is true.
Sub ShuffleText(Text As String, Key As String) As String
Dim x, y As Int
Dim NewText As String
For x = 0 To Key.Length - 1
NewText = ""
For y = 0 To Text.Length - 1
NewText = NewText & Chr( Bit.Xor(Asc(Key.CharAt(x)), Asc(Text.CharAt(y))))
Next
Text = NewText
Next
Return Text
End Sub