cryporange 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env sh
  2. #============HEADER=================================================|
  3. #AUTHOR
  4. # Jefferson Rocha <lrcjefferson@gmail.com>
  5. #
  6. #PROGRAM
  7. # CRYPORANGE - Acid Cryptography
  8. #
  9. #DESCRIPTION
  10. #
  11. #
  12. #TEST-ON
  13. # bash, zsh, ksh [OK]
  14. #
  15. #CHANGELOG
  16. # V2.0 (Jefferson Rocha)
  17. # - add variable RANDOM 'uhul', for more randomness.
  18. # - add 2 functions, shuffles and deshuffles for to change
  19. # some letters.
  20. # - base32 is also being used, with base64.
  21. #===================================================================|
  22. #=====VARS===========================|
  23. version="2.0"
  24. archive="/tmp/.archive${RANDOM}"
  25. uhul="$RANDOM"
  26. #=Colors
  27. bold=$(tput bold)
  28. back_red=$(tput setab 1)
  29. back_green=$(tput setab 2)
  30. back_blue=$(tput setab 4)
  31. back_cyan=$(tput setab 6)
  32. fore_red=$(tput setaf 1)
  33. fore_green=$(tput setaf 2)
  34. end_color=$(tput sgr0)
  35. #====================================|
  36. #=====TESTS==========================|
  37. for conference in "base64" "base32" "tr" "rev"; do # Exist list? no bye!
  38. if ! type -p "$conference" >/dev/null 2>&1; then
  39. printf '%b' "${bold}${fore_red}NEED '${conference}' TO CONTINUE${end_color}\n"
  40. exit 1
  41. fi
  42. done
  43. #====================================|
  44. #=====FUNCTIONS======================|
  45. remove(){
  46. if [ -e "$archive" ];then
  47. rm "$archive" >/dev/null 2>&1
  48. fi
  49. }
  50. _USAGE(){
  51. cat <<END | less
  52. CRYPORANGE $version
  53. User Manual.
  54. What is cryporange?
  55. Cryporange uses simple, more functional encryption!
  56. As a base it has the cipher of cesar, reverse and base64.
  57. United all on one base, that's cryptorange! good fun!
  58. ENCRYPT
  59. To encrypt a message, you must select option (1), after you write
  60. your message, for end, press <ENTER> then CTRL + D for encrypt your
  61. message.
  62. DECRYPT
  63. To decrypt a message, you must select option (2) menu.
  64. After this you paste your message encrypted, press <ENTER> then CTRL + D
  65. for decrypt.
  66. AUTHOR
  67. 2018 Jefferson Rocha <lrcjefferson@gmail.com>
  68. BUGS
  69. Send a message to lrcjefferson at gmail dot com
  70. (RETURN? PRESS Q)
  71. END
  72. }
  73. shuffles(){
  74. sed \
  75. "s/ /++!@/g; s/,/$uhul/g; s/a/t-!/g; s/e/$-/g; s/i/__/g; s/r/I@/g"
  76. }
  77. deshuffles(){
  78. sed \
  79. "s/++!@/ /g; s/$uhul/,/g; s/t-!/a/g; s/$-/e/g; s/__/i/g; s/I@/r/g"
  80. }
  81. _crypt(){
  82. printf '%b' "+-+-+-+- ENCRYPT MODE -+-+-+-+\n"
  83. printf '%b\n' "${bold}${fore_red}Enter TEXT. (NEW LINE and CTRL+D for CRYPT MESSAGE).${end_color}"
  84. # Print stdout.
  85. cat > "$archive" # Write a text
  86. [ ! -e "$archive" ] && exit 0 # Archive no exit? bye.
  87. cat "$archive" | \
  88. tr '[a-z]' '[x-za-w]' | \
  89. shuffles | \
  90. base32 | \
  91. rev | \
  92. base64
  93. remove # Remove .archive in /tmp
  94. }
  95. _decrypt(){
  96. printf '%b' "+-+-+-+- DECRYPT MODE -+-+-+-+\n"
  97. printf '%b\n' "${bold}${fore_red}PASTE TEXT: (NEW LINE and CTRL+D for DECRYPT MESSAGE).${end_color}"
  98. cat > "$archive"
  99. [ ! -e "$archive" ] && exit 0 # Archive no exist? BYE.
  100. cat "$archive" | \
  101. base64 -d | \
  102. rev | \
  103. base32 -d | \
  104. deshuffles | \
  105. tr '[x-za-w]' '[a-z]'
  106. remove # Remove .archive in /tmp
  107. }
  108. #====================================|
  109. # MAIN
  110. remove # Remove .archive in /tmp
  111. clear # <3 Clean
  112. cat << RANGER
  113. ${bold}${fore_green}
  114. ____ ____ _ _ ___ ____ ____ ____ _ _ ____ ____
  115. | |__/ \_/ |__] | | |__/ |__| |\ | | __ |__
  116. |___ | \ | | |__| | \ | | | \| |__] |___
  117. Acid Cryptography V${version} ${back_red} ${back_green} ${back_blue} ${back_cyan} ${end_color}
  118. ____________________________________________________
  119. RANGER
  120. PS3=$'\n> '
  121. select menu in "Encrypt" "Decrypt" "Usage" "Exit"; do
  122. if [ "$REPLY" = "1" ]; then
  123. _crypt # Call Func
  124. elif [ "$REPLY" = "2" ]; then
  125. _decrypt # Call Func
  126. elif [ "$REPLY" = "3" ]; then
  127. _USAGE # Call Func
  128. elif [ "$REPLY" = "4" ]; then
  129. exit 0 # Bye
  130. else
  131. printf '%b' "\t${bold}${fore_red}INVALID OPTION!!!!${end_color}\n"
  132. fi
  133. done