Advertisement
tmz

Simple XOR EncDec

tmz
Aug 5th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.71 KB | None | 0 0
  1. using Posix;
  2.  
  3. //valac --pkg=posix xor.vala
  4.  
  5. static uint key = 123;
  6.  
  7.  
  8. char[] string_to_char_array(string str) {
  9.     char[] char_array = new char[str.length];
  10.  
  11.     for (int i = 0; i < str.length; i++){
  12.         char_array[i] = (char)str.get_char(str.index_of_nth_char(i));
  13.     }
  14.    
  15.     return char_array;
  16. }
  17.  
  18.  
  19. public static string XOR_EncryptDecrypt(string str)
  20. {
  21. char[] f = string_to_char_array(str);
  22. for (int i = 0; i < f.length; i++)
  23. {
  24. f[i] = (char)((uint)f[i] ^ key);
  25. }
  26. string result = (string)f;
  27. return result;
  28. }
  29.  
  30. void main()
  31. {
  32.  
  33. string to_enc = "a";
  34.  
  35. string enc = XOR_EncryptDecrypt(to_enc);
  36.  
  37. print("%s", enc);
  38. system("echo "+enc+" > aaa.txt"); //just to throw it into an archive
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement