mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Added Dart implementation
This commit is contained in:
20
Dart/xorencryption.dart
Normal file
20
Dart/xorencryption.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
String encryptDecrypt(String input) {
|
||||
var key = ['K', 'C', 'Q']; //Can be any chars, and any size array
|
||||
var output = [];
|
||||
|
||||
for(var i = 0; i < input.length; i++) {
|
||||
var charCode = input.codeUnitAt(i) ^ key[i % key.length].codeUnitAt(0);
|
||||
output.add(new String.fromCharCode(charCode));
|
||||
}
|
||||
|
||||
return output.join("");
|
||||
}
|
||||
|
||||
void main() {
|
||||
String encrypted = encryptDecrypt("kylewbanks.com");
|
||||
print("Encrypted:" + encrypted);
|
||||
|
||||
String decrypted = encryptDecrypt(encrypted);
|
||||
print("Decrypted:" + decrypted);
|
||||
}
|
||||
Reference in New Issue
Block a user