i am trying to get obscured email that was obscured by firewall. i found the solution in python but i don't know to do this in dart or flutter. here is the python code
r = int(encodedString[:2],16)
email = ''.join([chr(int(encodedString[i:i 2], 16) ^ r) for i in range(2, len(encodedString), 2)])
return email
print cfDecodeEmail('543931142127353935313e352e7a373b39') # usage
CodePudding user response:
In Python,
encodedString[:2]
/encodedString[i:i 2]
extract two characters fromencodedString
. The Dart equivalent (assuming ASCII characters) would beencodedString.substring(0, 2)
andencodedString(i, i 2)
respectively.The equivalent of Python's
''.join(list)
in Dart islist.join()
.The equivalent of a Python's list comprehensions (
[i for i in items]
) in Dart is collection-for
:[for (var i in items) i]
.The equivalent of Python's
for i in range(2, len(encodedString), 2)
in Dart is to use a basicfor
loop with a start, condition, and increment:for (var i = 2; i < encodedString.length; i = 2)
.In Python,
int(string, 16)
parsesstring
as a hexadecimal number. In Dart, useint.parse(string, radix: 16)
.In Python,
chr(integer)
creates a string from the specified code point. The equivalent in Dart isString.fromCharCode(integer)
.
Putting it all together:
String cfDecodeEmail(String encodedString) {
var r = int.parse(encodedString.substring(0, 2), radix: 16);
var email = [
for (var i = 2; i < encodedString.length; i = 2)
String.fromCharCode(
int.parse(encodedString.substring(i, i 2), radix: 16) ^ r,
)
].join();
return email;
}
void main() {
// Prints: [email protected]
print(cfDecodeEmail('543931142127353935313e352e7a373b39'));
}