> For the complete documentation index, see [llms.txt](https://chenyangwang.gitbook.io/mathematical-base-for-information-safety/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chenyangwang.gitbook.io/mathematical-base-for-information-safety/tuo-yuan-qu-xian/elgamal-jia-mi.md).

# ElGamal加密

> * **STEP1: 密钥准备**
>
>   选取素数$$p$$，获取$$p$$的一个原根$$r$$，一个秘密整数$$0\leq a\leq p-1$$
> * **STEP2: 公钥**$$\left(p,r,b\right)$$
>
>   $$b\equiv r^a\left(\mod p\right)$$
> * **STEP3: 加密信息**$$P$$
>
>   选取随机数$$1\leq k\leq p-2$$
>
>   $$\gamma=r^k\left(\mod p\right)$$
>
>   $$\delta\equiv P\cdot b^k\left(\mod p\right)$$
> * **STEP4: 解密**
>
>   $$D\left(C\right)=\overline{\gamma^a}\delta$$
