0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

daily alpacahack super-tomato writeup

0
Posted at

初投稿。
CTF初心者です。
Daily AlpacaHack 1/2のsuper-tomato解いたwriteupです。

ぴんくいろ の ぼうしょく は とまと を もとめて いる...

ubuntu に nc~~を入力すると

スクリーンショット 2026-03-24 210814.png

問題文のpythonファイルは

スクリーンショット 2026-03-24 193732.png

19行目にある通り、2048bitのランダムな素数のPと、1024bitのランダムな素数のa、を使って、Aのchoice乗をpで割った余りが1になるような整数choiceを求める問題。

桁数が小さい場合は全探索でごり押してもいいけど、今回の場合は、2つの数とも桁数が凄いことになってるのでそんなことしてたら処理が終わりそうにありません。

ここで、choiceを求める方法として、フェルマーの小定理というものがあります(調べるまで知らなかった。)

フェルマーの小定理とは、pが素数で、AがPの倍数でない正の整数のとき

A^(P−1)≡1(modP)

が成り立つことだそうです。凄いですね。
そして、choice=p-1 とすればflagが得られます。
というのも、そもそも、pは2048bitの素数でaは1024bitの素数で、互いに素(2つの整数の最大公約数が1。例えば、2と5とか。)の自然数なのでフェルマーの小定理を使えます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?