asymmetric_cipher.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #parse argument
  2. architecture=$1
  3. permutation=$2
  4. matrix_decompressed_file=$3
  5. matrix_comp_file=$4
  6. output_dir=$5
  7. lorem_ipsum_file=$6
  8. if [ $permutation -eq 0 ] ; then
  9. permutation_str=""
  10. else
  11. permutation_str=" -no-permutation-key "
  12. fi
  13. # generate keys
  14. str="
  15. xrnlib-cli \
  16. --encoding-conf -compiled-param -no-password \
  17. --permutation-conf -arch $architecture $permutation_str \
  18. --make-monomial-key -monomial-key $output_dir/asym_enc_monomial_key_file.xf
  19. "
  20. echo ""; echo $str; echo ""
  21. eval $str
  22. str="
  23. xrnlib-cli \
  24. --decoding-conf -compiled-param -no-password \
  25. --encoding-conf -compiled-param -no-password \
  26. --sequence-conf -xmatrix $matrix_decompressed_file \
  27. --permutation-conf -arch $architecture $permutation_str \
  28. --make-start-point -start-point $output_dir/asym_enc_start_point_file.xf
  29. "
  30. echo ""; echo $str; echo ""
  31. eval $str
  32. str="
  33. xrnlib-cli \
  34. --decoding-conf -compiled-param -no-password \
  35. --encoding-conf -compiled-param -no-password \
  36. --arithmetic-conf -start-point $output_dir/asym_enc_start_point_file.xf -monomial-key $output_dir/asym_enc_monomial_key_file.xf \
  37. --sequence-conf -xmatrix $matrix_decompressed_file \
  38. --permutation-conf -arch $architecture \
  39. --make-binomial-key -binomial-key $output_dir/asym_enc_binomial_key_file.xf
  40. "
  41. echo ""; echo $str; echo ""
  42. eval $str
  43. # encrypt
  44. str="
  45. xrnlib-cli \
  46. --decoding-conf -compiled-param -no-password \
  47. --encoding-conf -compiled-param -no-password \
  48. --arithmetic-conf -binomial-key $output_dir/asym_enc_binomial_key_file.xf \
  49. --sequence-conf -xmatrix $matrix_decompressed_file \
  50. --permutation-conf -arch $architecture \
  51. --encrypt-asymmetric -plain-text $lorem_ipsum_file -cipher-text $output_dir/asym_enc_lorem_ipsum_file
  52. "
  53. echo ""; echo $str; echo ""
  54. eval $str
  55. # decrypt
  56. str="
  57. xrnlib-cli \
  58. --decoding-conf -compiled-param -no-password \
  59. --arithmetic-conf -monomial-key $output_dir/asym_enc_monomial_key_file.xf \
  60. --sequence-conf -xmatrix $matrix_decompressed_file \
  61. --permutation-conf -arch $architecture \
  62. --decipher-asymmetric -plain-text $output_dir/asym_enc_lorem_ipsum_file_decyphered -cipher-text $output_dir/asym_enc_lorem_ipsum_file
  63. "
  64. echo ""; echo $str; echo ""
  65. eval $str
  66. str="
  67. cmp --silent $output_dir/asym_enc_lorem_ipsum_file_decyphered $lorem_ipsum_file && echo 'PASS' || echo 'FAIL'
  68. "
  69. echo ""; echo $str; echo ""
  70. eval $str
  71. # permute cypher
  72. cat $output_dir/asym_enc_lorem_ipsum_file | sed 's/$/?/' > $output_dir/asym_enc_lorem_ipsum_file_wrong
  73. # perform decryption
  74. str="
  75. xrnlib-cli \
  76. --decoding-conf -compiled-param -no-password \
  77. --arithmetic-conf -monomial-key $output_dir/asym_enc_monomial_key_file.xf \
  78. --sequence-conf -xmatrix $matrix_decompressed_file \
  79. --permutation-conf -arch $architecture \
  80. --logging-conf -lib-error-log $output_dir/wrong_lib_info_log_file.xf \
  81. --decipher-asymmetric -plain-text $output_dir/asym_enc_lorem_ipsum_file_decyphered_wrong -cipher-text $output_dir/asym_enc_lorem_ipsum_file_wrong "
  82. echo ""; echo $str; echo ""
  83. eval $str
  84. str="
  85. if [ ! -s $output_dir/wrong_lib_info_log_file.xf ] ; then echo 'FAIL' ; exit ; fi
  86. "
  87. echo ""; echo $str; echo ""
  88. eval $str
  89. str="
  90. cmp --silent $output_dir/asym_enc_lorem_ipsum_file_decyphered_wrong $lorem_ipsum_file && echo 'FAIL'
  91. "
  92. echo ""; echo $str; echo ""
  93. eval $str