@TOC


本文参考如下博文:
CTF中的加密问题
鉴于自己学习需要对其整理,感谢大佬们!

一、gmpy2库安装问题:

首先我在安装好pip2 pip3 python2 python3 的前提下:

1.执行pip install gmpy2 pip2 install gmpy2

   pip install gmpy2
   pip2 install gmpy2

两条命令均报错且并非可得错误(src/gmpy.h:252:20: fatal error: mpfr.h: 没有那个文件或目录),其实pip默认采用的是pip2

──(root💀kali01)-[/home/dc/Desktop]
└─# pip install gmpy2
ERROR: Could not find a version that satisfies the requirement gmpy2 (from versions: none)
ERROR: No matching distribution found for gmpy2

┌──(root💀kali01)-[/home/dc/Desktop]
└─# pip2 install gmpy2 1
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting gmpy2
Downloading gmpy2-2.0.8.zip (280 kB)
|████████████████████████████████| 280 kB 1.0 MB/s
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-646jTE/gmpy2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-646jTE/gmpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-mcHQge
cwd: /tmp/pip-install-646jTE/gmpy2/
Complete output (6 lines):
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

error: invalid command 'egg_info'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

2.执行pip3 install gmpy2

得到了想要的结果

┌──(root💀kali01)-[/home/dc/Desktop]
└─# pip3 install gmpy2 1
Collecting gmpy2
Using cached gmpy2-2.0.8.zip (280 kB)
Building wheels for collected packages: gmpy2
Building wheel for gmpy2 (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-9swayh2v
cwd: /tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
building 'gmpy2' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-euU3fN/python3.9-3.9.1=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/build/python3.9-euU3fN/python3.9-3.9.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITHMPFR -DWITHMPC -I/usr/include/python3.9 -c src/gmpy2.c -o build/temp.linux-x86_64-3.9/src/gmpy2.o
In file included from src/gmpy2.c:426:
src/gmpy.h:252:12: fatal error: mpfr.h: No such file or directory
252 | # include "mpfr.h"
| ^~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for gmpy2
Running setup.py clean for gmpy2
Failed to build gmpy2
Installing collected packages: gmpy2
Running setup.py install for gmpy2 ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9_0wm_0q/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/gmpy2
cwd: /tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/
Complete output (14 lines):
running install
running build
running build_ext
building 'gmpy2' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-euU3fN/python3.9-3.9.1=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/build/python3.9-euU3fN/python3.9-3.9.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITHMPFR -DWITHMPC -I/usr/include/python3.9 -c src/gmpy2.c -o build/temp.linux-x86_64-3.9/src/gmpy2.o
In file included from src/gmpy2.c:426:
src/gmpy.h:252:12: fatal error: mpfr.h: No such file or directory
252 | # include "mpfr.h"
| ^~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jgky7gnw/gmpy2_4bd9a6299dba4742852f6412aa414f89/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-9_0wm_0q/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/gmpy2 Check the logs for full command output.

3.从 ftp://ftp.gnu.org/gnu/mpfr/ 下载最新的mpfr的压缩包

这里下载的是 mpfr-3.1.5.zip
在Kali中执行以下命令:(在对应的文件下执行)

unzip mpfr-3.1.5.zip 
cd mpfr-3.1.5
./configure
make
make check
VERBOSE=1 make check
make install

4.从 ftp://gcc.gnu.org/pub/gcc/infrastructure/ 下载最新的mpc压缩包

这里下载的是 mpc-1.0.3.tar.gz , Kali 中执行以下命令:

tar -xzvf  mpc-1.0.3.tar.gz    
cd mpc-1.0.3
./configure
make
make install

5.缺少libmpfr.so.4,解决办法

locate libmpfr
gedit /etc/ld.so.conf 将上面的那些目录贴进去
ldconfig

在这里若遇到gedit出现问题就要安装gedit
gedit安装

6.python3下导入gmpy2无错

┌──(root💀kali01)-[/home/dc/Desktop]
└─# pip3 install gmpy2
Requirement already satisfied: gmpy2 in /usr/local/lib/python3.9/dist-packages (2.0.8)
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv

┌──(root💀kali01)-[/home/dc/Desktop]
└─# python3
Python 3.9.1+ (default, Feb 5 2021, 13:46:56)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy2
>>> exit()

但是python2无法用:

┌──(root💀kali01)-[/home/dc/Desktop]
└─# pip2 install gmpy2
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting gmpy2
Using cached gmpy2-2.0.8.zip (280 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3RFkaS/gmpy2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3RFkaS/gmpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-xAzmXF
cwd: /tmp/pip-install-3RFkaS/gmpy2/
Complete output (6 lines):
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

error: invalid command 'egg_info'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

参考这个:

Linux下安装gmpy2
tar.zst文件解压
在最后一步安装出错
python2 setup.py install 报错
出错详细参考此篇:
安装包时报错error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
继续运行
在这里插入图片描述

7.python2导入gmpy2成功(参考上文解决)

在这里插入图片描述

8.终于解出那道题了

在这里插入图片描述

二、使用步骤

1.引入库

代码如下(示例):

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

2.读入数据

代码如下(示例):

data = pd.read_csv(
'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())

该处使用的url网络请求的数据。


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。