Created
February 10, 2021 14:55
-
-
Save mollifier/ac2415fd77a47038824d55cdb5d49b7b to your computer and use it in GitHub Desktop.
RSA暗号で復号化するシェルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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