Skip to content

Instantly share code, notes, and snippets.

@mollifier
Created February 10, 2021 14:55
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/ac2415fd77a47038824d55cdb5d49b7b to your computer and use it in GitHub Desktop.
Save mollifier/ac2415fd77a47038824d55cdb5d49b7b to your computer and use it in GitHub Desktop.
RSA暗号で復号化するシェルスクリプト
#!/bin/bash
# RSA暗号で復号化します
# 使い方
# rsa_decrypt.sh -d 秘密鍵dのファイル -n 公開鍵nのファイル 暗号文となる数字
# 例
# rsa_decrypt.sh -d private_key_a/d.txt -n public_key/n_a.txt 16
set -e
d_file=
n_file=
encrypted_text=
while getopts d:n: option
do
case "$option" in
d)
d_file=$OPTARG
;;
n)
n_file=$OPTARG
;;
\?)
exit 1
;;
esac
done
shift $((OPTIND - 1))
encrypted_text=$1
d=$(cat "$d_file")
n=$(cat "$n_file")
echo $(( encrypted_text ** d % n ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment