Skip to content

Instantly share code, notes, and snippets.

@mollifier
Last active February 10, 2021 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mollifier/b62a68898edcf174de422559926198d9 to your computer and use it in GitHub Desktop.
Save mollifier/b62a68898edcf174de422559926198d9 to your computer and use it in GitHub Desktop.
RSA暗号で暗号化するシェルスクリプト
#!/bin/bash
# RSA暗号で暗号化します
# 使い方
# rsa_encrypt.sh -e 公開鍵eのファイル -n 公開鍵nのファイル 平文となる数字
# 例
# rsa_encrypt.sh -n public_key/n_a.txt -e public_key/e_a.txt 4
set -e
e_file=
n_file=
cleartext=
while getopts e:n: option
do
case "$option" in
e)
e_file=$OPTARG
;;
n)
n_file=$OPTARG
;;
\?)
exit 1
;;
esac
done
shift $((OPTIND - 1))
cleartext=$1
n=$(cat "$n_file")
e=$(cat "$e_file")
echo $(( cleartext ** e % n ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment