ContainerKey.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace System.Fire.Container {
  7. public class ContainerKey {
  8. private byte[] _k;
  9. public ContainerKey() {
  10. }
  11. public ContainerKey(byte[] Key) {
  12. this._k = Key;
  13. }
  14. public byte[] Key {
  15. get {
  16. return this._k;
  17. }
  18. set {
  19. this._k = value;
  20. }
  21. }
  22. public byte GetAt(int index) {
  23. return this._k[index % this._k.Length];
  24. }
  25. public int Length {
  26. get {
  27. return this._k.Length;
  28. }
  29. }
  30. public static byte[] operator |(ContainerKey key, byte[] s) {
  31. byte[] res = new byte[s.Length];
  32. for (int i = 0, c = s.Length; i < c; i++)
  33. res[i] = (byte)(s[i] | key.GetAt(i));
  34. return res;
  35. }
  36. public static byte[] operator &(ContainerKey key, byte[] s) {
  37. byte[] res = new byte[s.Length];
  38. for (int i = 0, c = s.Length; i < c; i++)
  39. res[i] = (byte)(s[i] & key.GetAt(i));
  40. return res;
  41. }
  42. public static byte[] operator ^(ContainerKey key, byte[] s) {
  43. byte[] res = new byte[s.Length];
  44. for (int i = 0, c = s.Length; i < c; i++)
  45. res[i] = (byte)(s[i] ^ key.GetAt(i));
  46. return res;
  47. }
  48. public static byte[] operator |(ContainerKey key, string s) {
  49. return key | System.Text.ASCIIEncoding.Default.GetBytes(s);
  50. }
  51. public static byte[] operator &(ContainerKey key, string s) {
  52. return key & System.Text.ASCIIEncoding.Default.GetBytes(s);
  53. }
  54. public static byte[] operator ^(ContainerKey key, string s) {
  55. return key ^ System.Text.ASCIIEncoding.Default.GetBytes(s);
  56. }
  57. }
  58. }