Menu

ACMP 391. Взлом хеш-функции

January 31, 2017 - acmp.ru

Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int const maxn = int(1e5 + 12);
int const maxb = int(2e6 + 12);
int const inf = int(1e9 + 7);
ll const linf = ll(1e18 + 12);
double const eps = 1e-7;
double const pi = acos(-1);
#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define next MyLittleNext
//#define end MyLittleEnd
#define all(x) x.begin(), x.end()
//#define fn ""

int x, m, l, v;
int a[110];

int P()
{
	int ans = 0, X = 1;
	for (int i = 0; i < l; i++)
	{
		ans = (ans + a[i] * 1ll * X) % m;
		X = (X * 1ll * x) % m;
	}
	return ans;
}

int main()
{
	#ifdef fn
		freopen(fn ".in", "r", stdin);
		freopen(fn ".out", "w", stdout);
	#endif
	scanf("%d%d%d%d", &x, &m, &l, &v);
	do
	{
		for (int i = 0; i < l; i++)
			a[i] = rand() % 10;
	} while(P() != v);
	for (int i = 0; i < l; i++)
		printf("%d", a[i]);
}

(248)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VK

Author of this post : UnknownA AuthorA

Leave a Reply

Your email address will not be published. Required fields are marked *