Last active
February 10, 2021 14:56
-
-
Save mollifier/b62a68898edcf174de422559926198d9 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_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