Home > Software engineering >  How can i convert this obsucured decrypt python code in dart?
How can i convert this obsucured decrypt python code in dart?

Time:06-28

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 from encodedString. The Dart equivalent (assuming ASCII characters) would be encodedString.substring(0, 2) and encodedString(i, i 2) respectively.

  • The equivalent of Python's ''.join(list) in Dart is list.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 basic for loop with a start, condition, and increment: for (var i = 2; i < encodedString.length; i = 2).

  • In Python, int(string, 16) parses string as a hexadecimal number. In Dart, use int.parse(string, radix: 16).

  • In Python, chr(integer) creates a string from the specified code point. The equivalent in Dart is String.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'));
}
  • Related