Exemplo n.º 1
0
void print_shuffle_sequence_retries(int k, int retries_count, const char*id, const char*sequence)
{
	int l;
	char *t=NULL;
	int i;

	l = strlen(sequence);
	if ((t = malloc(l + 1)) == NULL)
		err(1,"malloc failed");
	t[l] = '\0';

	shuffle1(sequence, l, k);

	i = 0 ;
	while ( i < retries_count ) {
		shuffle2(t);
		if (strncmp(sequence, t, l) != 0) {
			printf("%s\n", id);
			printf("%s\n", t);
			break;
		}
		i++;
	}
	if (i>=retries_count) {
		fprintf(stderr,"WARNING: failed to find new shuffle for sequence \"%s\" (%s) after %d retries\n", id, sequence, retries_count);
		printf("%s\n", id);
		printf("%s\n", t);
	}
	shuffle_reset();

	free(t);
}
Exemplo n.º 2
0
void
shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
	unsigned char *target)
{
	int b2, d, s;
	buf32 temp;

	while ((buflen > 0)
	       && (buf[buflen - 1] == 0))
	{
		buflen = buflen - 1;
	}

	for (s = 0; s < 32; s++)
	{
		temp[s] = 0;
	}

	d = 0;
	while (buflen >= 32)
	{
		for (s = 0; s <= 31; ++s)
		{
			temp[s] = temp[s] ^ buf[d];
			d = d + 1;
		}
		buflen = buflen - 32;
	}
	b2 = d;
	if (buflen > 0)
	{
		for (s = 0; s <= 31; ++s)
		{
			if (d + buflen == b2)
			{
				b2 = d;
				temp[s] = temp[s] ^ encryptkeys[s];
			} else
			{
				temp[s] = temp[s] ^ buf[b2];
				b2 = b2 + 1;
			}
		}
	}
	for (s = 0; s <= 31; ++s)
		temp[s] = temp[s] ^ lon[s & 3];

	shuffle1(temp, target);
}
static PyObject *ushuffle_shuffle1(PyObject *self, PyObject *args) {
	const char *s;
	const int l;
	const int k;

	/* example python call: ushuffle.shuffle1('string', 6, 2) */
	if (!PyArg_ParseTuple(args, "sii", &s, &l, &k)) {
		l_ = 0;
		return NULL;
	}

	l_ = l;
	shuffle1(s, l, k);
	Py_INCREF(Py_None);
	return Py_None;
}
Exemplo n.º 4
0
void print_shuffle_sequence_perm(int k, int permutations_count, const char*id, const char*sequence)
{
	int l;
	char *t=NULL;
	int i;

	l = strlen(sequence);
	if ((t = malloc(l + 1)) == NULL)
		err(1,"malloc failed");
	t[l] = '\0';

	shuffle1(sequence, l, k);
	for (i = 0; i < permutations_count; i++) {
		shuffle2(t);
		printf("%s-perm%d\n", id, i+1);
		printf("%s\n", t);
	}
	shuffle_reset();

	free(t);
}
Exemplo n.º 5
0
void shuffle(const char *s, char *t, int l, int k) {
	shuffle1(s, l, k);
	shuffle2(t);
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
	char *s = NULL, *t;
	int n = 1, k = 2, b = 0;
	struct rusage r1, r2;
	struct timeval t1, t2;
	struct timeval tv;
	double u1;
	unsigned long seed;
	int i, l;

	gettimeofday(&tv, NULL);
	seed = (unsigned long) tv.tv_sec;

	for (i = 1; i < argc; i++)
		if (!strcmp(argv[i], "-s")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				s = argv[++i];
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-n")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				n = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-k")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				k = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-seed")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				seed = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-b"))
			b = 1;
	if (n <= 0 || s == NULL)
		print_help_and_exit();

	l = strlen(s);
	if ((t = malloc(l + 1)) == NULL) {
		fprintf(stderr, "malloc failed\n");
		exit(1);
	}
	t[l] = '\0';
	srandom(seed);
	set_randfunc((randfunc_t) random);
	if (b)
		getrusage(RUSAGE_SELF, &r1);
	shuffle1(s, l, k);
	for (i = 0; i < n; i++) {
		shuffle2(t);
		if (!b)
			printf("%s\n", t);
	}
	if (b) {
		getrusage(RUSAGE_SELF, &r2);
		t1 = r1.ru_utime;
		t2 = r2.ru_utime;
		u1 = (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) * 0.001;
		printf("%g\n", u1);				/* time in msec */
	}
	return 0;
}