Exemple #1
0
static uint32_t synthSound (B3S *instance, uint32_t written, uint32_t nframes, float **out) {
  B3S* b3s = (B3S*)instance;

  while (written < nframes) {
    int nremain = nframes - written;

    if (b3s->boffset >= BUFFER_SIZE_SAMPLES)  {
      b3s->boffset = 0;
      oscGenerateFragment (instance->inst->synth, b3s->bufA, BUFFER_SIZE_SAMPLES);
      preamp (instance->inst->preamp, b3s->bufA, b3s->bufB, BUFFER_SIZE_SAMPLES);
      reverb (instance->inst->reverb, b3s->bufB, b3s->bufC, BUFFER_SIZE_SAMPLES);
#ifdef WITH_SIGNATURE
      scramble (b3s, b3s->bufC, BUFFER_SIZE_SAMPLES);
#endif
      whirlProc3(instance->inst->whirl, b3s->bufC, b3s->bufL[0], b3s->bufL[1], b3s->bufD[0], b3s->bufD[1], BUFFER_SIZE_SAMPLES);

    }

    int nread = MIN(nremain, (BUFFER_SIZE_SAMPLES - b3s->boffset));

    memcpy(&out[0][written], &b3s->bufL[0][b3s->boffset], nread*sizeof(float));
    memcpy(&out[1][written], &b3s->bufL[1][b3s->boffset], nread*sizeof(float));

    written+=nread;
    b3s->boffset+=nread;
  }
  return written;
}
Exemple #2
0
static void generateSignatureVector(DSA* key, unsigned char* mess, int len, BOOL passes)
{
    unsigned char buf[len];
    unsigned int siglen;
    int err;
    DSA_SIG* sig;

    Mem::Copy(buf, mess, len);

    setOurRandom();
    sig = DSA_do_sign(buf, len, key);
    if (sig == NULL)
        processError();

    if (!passes)
        scramble(buf, len);

    printActionHeader("DSA test vector", "DSASignVector");
    printDSAPrivateKey(key);
    printHexElement("digest", buf, len);
    printBNElement("sigR", sig->r);
    printBNElement("sigS", sig->s);
    printActionFooter(passes);

    printActionHeader("DSA test vector", "DSAVerifyVector");
    printDSAPublicKey(key);
    printHexElement("digest", buf, len);
    printBNElement("sigR", sig->r);
    printBNElement("sigS", sig->s);
    printActionFooter(passes);

    DSA_SIG_free(sig);
}
Exemple #3
0
/* Decode the string in place. */
char *
descramble (char *str)
{
    char *s;
    int i;

    /* For now we can only handle one kind of scrambling.  In the future
       there may be other kinds, and this `if' will become a `switch'.  */
    if (str[0] != 'A')
#ifndef DIAGNOSTIC
	error (1, 0, "descramble: unknown scrambling method");
#else  /* DIAGNOSTIC */
    {
	fprintf (stderr, "descramble: unknown scrambling method\n", str);
	fflush (stderr);
	exit (EXIT_FAILURE);
    }
#endif  /* DIAGNOSTIC */

    /* Method `A' is symmetrical, so scramble again to decrypt. */
    s = scramble (str + 1);

    /* Shift the whole string one char to the left, pushing the unwanted
       'A' off the left end.  Safe, because s is null-terminated. */
    for (i = 0; s[i]; i++)
	s[i] = s[i + 1];

    return s;
}
Exemple #4
0
/*_____________________________________________________________________________
**      function name: rand
**      descriptions:
**           Random value generation. 
**             
**      parameters:
**            None
**             
**      global:
**            None
**             
**      return:
**            Random value
**	     
**      call:
**            timerVlrGet
**      	
**      revision:
**      1. Here 2008/08/24
**____________________________________________________________________________
*/
uint32
rand(void){
	uint32 vlr;
	timerVlrGet(1, vlr);
	scramble(vlr);
	return (vlr & RAND_MAX);
}/*end rand*/
int                     brute_cvsroot(void)
{
    int                 i, ret = 0;
    char                * rbuf;

    info("Bruteforcing cvsroot...\n");
    for (i = 0; CVSROOTS[i].name; i++)
        {
            nopen(host, port);
            nprintf(CVS_VERIF, CVSROOTS[i].name, DUMMY, scramble(DUMMY));
            info("Trying CVSROOT = %s\t", CVSROOTS[i].name);
            rbuf = flush_sock();
            nclose();
            if (!rbuf || strstr(rbuf, CVS_BAD_REP))
                info(BAD_TRIP);
            else if (strstr(rbuf, CVS_AUTH_FAILED) ||
                     strstr(rbuf, CVS_AUTH_SUCCESS) ||
                     strstr(rbuf, CVS_NO_USER))
                {
                    info(GOOD_TRIP);
                    CVSROOTS[i].id = i;
                    root = CVSROOTS[i].name;
                    if (user && pass)
                        {
                            free(rbuf);
                            return (1);
                        }
                    ret++;
                }
            else
                printf(BAD_TRIP);
            free(rbuf);
        }
    return (ret);
}
/**
 * Transmit APRS log packet
 */
uint32_t aprs_encode_log(uint8_t* message, mod_t mod)
{
	ax25_t packet;
	packet.data = message;
	packet.max_size = 512; // TODO: replace 512 with real size
	packet.mod = mod;

	// Encode APRS header
	ax25_send_header(&packet, APRS_CALLSIGN, APRS_SSID, APRS_PATH);
	ax25_send_string(&packet, "{{L");

	// Encode log message
	uint8_t i;
	for(i=0; i<LOG_TRX_NUM; i++) {
		gpsFix_t dummy;
		gpsFix_t *data = &dummy; // TODO: Implement getNextLogPoint() for this assignment
		uint8_t base64[BASE64LEN(sizeof(gpsFix_t))+1];
		base64_encode((uint8_t*)data, base64, sizeof(gpsFix_t));
		ax25_send_string(&packet, (char*)base64);
	}

	// Send footer
	ax25_send_footer(&packet);
	nrzi_encode(&packet);
	scramble(&packet);

	return packet.size;
}
Exemple #7
0
//*************************************************************
int main(void)
{
   while (1) {
      scramble(5, 5, 5) ;
      getch() ;
   }
   // return 0;
}
Exemple #8
0
static void fct_noscale(double *f)
{
  scramble(f,N);
  fwd_butterflies(f);
  bitrev(f,N);
  fwd_sums(f);
  f[0] *= INVROOT2;
}
Exemple #9
0
int
main(int argc, char **argv)
{
  unsigned long mod;
  hash_table_t table = HASH_TABLE_INIT(0x80010000 | HASH_FLAG_AUTOGROW,
				       check_func, check_comp, 0, 0);

  /* Check that the static initializer produces a passable structure */
  check_init(&table, HASH_FLAG_AUTOGROW, 0, 0, 0, check_func, check_comp,
	     0, "ht_static");

  /* now, check what ht_init does with bad arguments */
  check_result(ht_init(0, 0, 0, 0, 0, 0, 0), DB_ERR_BADARGS, "ht_init_noargs",
	       "ht_init() with no valid arguments", 0);
  check_result(ht_init(0, 0, check_func, check_comp, 0, 0, 0), DB_ERR_BADARGS,
	       "ht_init_notable", "ht_init() with no table", 0);
  check_result(ht_init(&table, 0, 0, check_comp, 0, 0, 0), DB_ERR_BADARGS,
	       "ht_init_nofunc", "ht_init() with no hash function", 0);
  check_result(ht_init(&table, 0, check_func, 0, 0, 0, 0), DB_ERR_BADARGS,
	       "ht_init_nocomp", "ht_init() with no comparison function", 0);

  /* Scramble the structure */
  scramble(&table);

  /* Now try to initialize our structure with a 0 mod and see what happens */
  check_result(ht_init(&table, 0x80010000 | HASH_FLAG_AUTOGROW, check_func,
		       check_comp, 0, 0, 0), 0, "ht_dynamic_nomod",
	       "ht_init() with zero modulus", 0);
  check_init(&table, HASH_FLAG_AUTOGROW, 0, 0, 0, check_func, check_comp,
	     0, "ht_dynamic_nomod");

  /* Scramble the structure again */
  scramble(&table);

  /* Now try to initialize our structure with a non-0 mod and see what
   * happens
   */
  check_result(ht_init(&table, 0x80010000 | HASH_FLAG_AUTOGROW, check_func,
		       check_comp, 0, 0, 6), 0, "ht_dynamic_mod6",
	       "ht_init() with non-zero modulus", 0);
  mod = 7; /* next prime after 6 */
  check_init(&table, HASH_FLAG_AUTOGROW, mod, (mod * 4) / 3, (mod * 3) / 4,
	     check_func, check_comp, 0, "ht_dynamic_mod6");

  return 0;
}
Exemple #10
0
/* http://www.redferni.uklinux.net/mysql/MySQL-Protocol.html */ 
int MySQLPrepareAuth(_MYSQL_DATA *_psSessionData, char* szLogin, char* szPassword, char* szSessionSalt, unsigned char** szResponse, unsigned long* iResponseLength)
{
  unsigned char* response;
  /* usernames limited to 16 characters - http://dev.mysql.com/doc/refman/5.1/en/user-names.html */
  int login_len = strlen(szLogin) > 16 ? 16 : strlen(szLogin);
  int response_len = 4  /* header */  +
                     4  /* client flags */  +
                     4  /* max packet len */  +
                     1  /* charset */ +
                     23 /* future expansion */ +
                     login_len /* username */ +
                     1 /* NULL termination */ + 
                     1; /* password length */
    
  if ( strcmp(szPassword, "") != 0 ) /* password set */
    response_len += 20;

  response = (unsigned char *) malloc(response_len + 1);
  memset(response, 0, response_len + 1);

  response[0] = response_len - 4;     /* packet body length - exclude header */
  response[1] = 0x00;
  response[2] = 0x00;
  response[3] = 0x01;                 /* packet number */
  
  //response[4] = 0x85;               /* client flag */
  response[4] = 0x05;                 /* client flag */
  //response[5] = 0x24;
  response[5] = 0xa6;
  response[6] = 0x03;
  response[7] = 0x00;
  
  response[8] = 0x00;                 /* max packet */
  response[9] = 0x00;
  response[10] = 0x00;    
  response[11] = 0x01;    
  
  response[12] = 0x21;                /* charset utf8 */

  strncpy((char*)response + 36, szLogin, login_len);  /* NULL terminated username */

  if ( strcmp(szPassword, "") == 0 ) /* no password set */
  {
    response[36 + login_len + 1] = 0x00;
  }
  else
  {
    response[36 + login_len + 1] = 0x14;  /* set length of scrambled password - 0x14 (20) */

    /* generate SHA password hash */
    scramble((char *) &response[36 + login_len + 1 + 1], _psSessionData, szSessionSalt, szPassword); 
  }
  
  *(iResponseLength) = response_len; 
  *szResponse = response;
  return SUCCESS;
}
Exemple #11
0
int main(int argc, char **argv)
{
	unsigned char *buf = (unsigned char *)argv[1];
	int l = strlen((char *)buf);
	printf("original   :"); hexdump(buf, l);
	scramble(buf, l);
	printf("scrambled  :"); hexdump(buf, l);
	unscramble(buf, l);
	printf("unscrambled:"); hexdump(buf, l);
}
Exemple #12
0
TPuzzleView::TPuzzleView(TRect& r) :
        TView(r) {
    srand (time(NULL));options |= ofSelectable;
    memset(board, ' ', sizeof(board));

    for (int i = 0; i <= 3; i++)
    for (int j = 0; j <= 3; j++)
    board[i][j] = boardStart[i * 4 + j];

    scramble();
}
Exemple #13
0
static int
pcauth(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	String sys, id, pw, cm;
	Unixidmap *m;
	int uid;

	chat("host=%I, port=%ld: pcauth...",
		cmd->host, cmd->port);
	if(n <= 16)
		return garbage(reply, "count too small");
	argptr += string2S(argptr, &sys);
	argptr += string2S(argptr, &id);
	argptr += string2S(argptr, &pw);
	argptr += string2S(argptr, &cm);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	scramble(&id);
	scramble(&pw);

	m = pair2idmap("pcnfsd", cmd->host);
	uid = -1;
	if(m)
		uid = name2id(&m->u.ids, id.s);
	if(uid < 0)
		uid = 1;
	chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s,
		utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s);
	PLONG(0);	/* status - OK */
	PLONG(uid);
	PLONG(uid);	/* gid */
	PLONG(0);	/* ngids */
	PLONG(sizeof(pc_home)-1);
	PPTR(pc_home, sizeof(pc_home)-1);
	PLONG(0);	/* umask */
	PLONG(sizeof(no_comment)-1);
	PPTR(no_comment, sizeof(no_comment)-1);
	return dataptr - (uchar *)reply->results;
}
int                     do_auth(void)
{
    char                * your_mind;

    nopen(host, port);
    nprintf(CVS_LOGIN, root, user, scramble(pass));
    your_mind = flush_sock();
    if (!strstr(your_mind, CVS_AUTH_SUCCESS))
        QUIT(ERR_AUTHFAILED);
    free(your_mind);
    nprintf(CVS_SEND_ROOT, root);
}
Exemple #15
0
/*
 * Inverse Complex Fourier Transform
 */
void
icfft(COMPLEX *dat, int num)
{
    /* Check for trig table initialization */
    if (num != _init_size) {
	if (init_sintab(num) == 0) {
	    /* Can't do requested size */
	    return;
	}
    }

    scramble(num, dat);
    butterflies(num, 1, dat);
}
Exemple #16
0
int
dc_scramble (void)
{
    char dest_name[FILENAME_MAX];

    strcpy (dest_name, ucon64.fname);
    ucon64_file_handler (dest_name, NULL, 0);

    if (!scramble (ucon64.fname, ucon64.file_size, dest_name))
        printf (ucon64_msg[WROTE], dest_name);
    else
        fprintf (stderr, ucon64_msg[WRITE_ERROR], dest_name);
    return 0;
}
Exemple #17
0
/**
 * Transmit APRS telemetry configuration
 */
uint32_t aprs_encode_telemetry_configuration(uint8_t* message, mod_t mod, telemetryConfig_t type)
{
	char temp[4];
	ax25_t packet;
	packet.data = message;
	packet.max_size = 512; // TODO: replace 512 with real size
	packet.mod = mod;

	ax25_send_header(&packet, APRS_CALLSIGN, APRS_SSID, APRS_PATH); // Header
	ax25_send_byte(&packet, ':'); // Message flag

	// Callsign
	ax25_send_string(&packet, APRS_CALLSIGN);
	ax25_send_byte(&packet, '-');
	chsnprintf(temp, sizeof(temp), "%d", APRS_SSID);
	ax25_send_string(&packet, temp);

	ax25_send_string(&packet, " :"); // Message separator

	switch(type) {
		case CONFIG_PARM:
			ax25_send_string(&packet, "PARM.Battery,Solar,Temp,Charge,Discharge");
			break;
		case CONFIG_UNIT:
			ax25_send_string(&packet, "UNIT.Volt,Volt,degC,mW,mW");
			break;
		case CONFIG_EQNS:
			ax25_send_string(&packet,
				"EQNS."
				"0,.001,0,"
				"0,.001,0,"
				"0,0.1,-100,"
				"0,1,0,"
				"0,1,0"
			);
			break;
		case CONFIG_BITS:
			ax25_send_string(&packet, "BITS.11111111,Pecan Balloon");
			break;
	}

	ax25_send_footer(&packet); // Footer
	nrzi_encode(&packet);
	scramble(&packet);
	
	return packet.size;
}
Exemple #18
0
/*
 * The main function.
 * @param argc The number of arguments.
 * @param argv The arguments themselves, in an arrag of strings (char *).
 * @return The exit value (EXIT_SUCCESS or EXIT_FAILURE).
 */
int
main (int argc, char **argv)
{
    FILE *io_pipes[2];

#ifdef ENABLE_NLS
    bindtextdomain (PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);
#endif

    seed (NULL);

    scramble (options (argc, argv, io_pipes), io_pipes);

    return EXIT_SUCCESS;
}
int do_attack(MYSQL *mysql, char *attackuser) {
   char buff[512], *pos=buff, *attackpasswd = "A";
   int i, len, j, ret = 1;

   pos = (char*)strmov(pos,attackuser)+1;
   mysql->scramble_buff[1] = 0;
   pos = scramble(pos, mysql->scramble_buff, attackpasswd,
               (my_bool) (mysql->protocol_version == 9));
   pos = (char*)strmov(pos+1,"");
   len = pos-buff;

   for (j = 0; ret && j < 32; j++) {
       buff[5] = 65 + j; 
       ret = simple_command(mysql,COM_CHANGE_USER, buff,(uint)len,0);
   }

   return ret;
}
Exemple #20
0
void TPuzzleView::handleEvent(TEvent& event) {
    TView::handleEvent(event);

    if (solved && (event.what & (evKeyboard | evMouse))) {
        scramble();
        clearEvent(event);
    }

    if (event.what == evMouseDown) {
        moveTile(event.mouse.where);
        clearEvent(event);
        winCheck();
    } else if (event.what == evKeyDown) {
        moveKey(event.keyDown.keyCode);
        clearEvent(event);
        winCheck();
    }
}
int                     brute_username(void)
{
    int                 i, c, ret = 0;
    char                * rbuf;

    info("Bruteforcing cvs login... \n");
    for (c = 0; CVSROOTS[c].name; c++)
        {
            if (!root && CVSROOTS[c].id == -1) continue;
            for ( i=0; USERNAMES[i].name; i++ )
                {
                    if (root)
                        CVSROOTS[c].name = root;
                    info("Trying cvsroot = %s, login = %s\t", CVSROOTS[c].name,
                         USERNAMES[i].name);
                    nopen(host, port);
                    nprintf(CVS_VERIF, CVSROOTS[c].name, USERNAMES[i].name,
                            scramble(DUMMY));
                    rbuf = flush_sock();
                    nclose();
                    if ( strstr( rbuf, CVS_NO_USER))
                        info( BAD_TRIP, rbuf );
                    else if (strstr( rbuf, CVS_AUTH_FAILED) ||
                        strstr(rbuf, CVS_AUTH_SUCCESS))
                        {
                            info(GOOD_TRIP);
                            USERNAMES[i].id = CVSROOTS[c].id;
                            user = USERNAMES[i].name;
                            if (pass)
                                {
                                    free(rbuf);
                                    return (1);
                                }
                            ret++;
                        }
                    free(rbuf);
                }
            if (root)
                return (ret);
        }
    return (ret);
}
Exemple #22
0
int main(int argc, char *argv[])
{
  int opt = 0;

  if(argc > 1 && !strcmp(argv[1], "-d"))
    opt ++;

  if(argc != 3+opt)
    {
      fprintf(stderr, "Usage: %s [-d] from to\n", argv[0]);
      exit(1);
    }
  
  if(opt)
    descramble(argv[2], argv[3]);
  else
    scramble(argv[1], argv[2]);

  return 0;
}
int                     brute_password(void)
{
    int                 i, c, ret=0;
    char                * rbuf;

    info("Bruteforcing cvs password...\n");
    for (c = 0; USERNAMES[c].name; c++)
        {
            if (!user && USERNAMES[c].id == -1) continue;
            for (i = 0; PASSWORDS[i].name; i++)
                {
                    info("Trying login = %s, pass = %s\t", user?user:USERNAMES[c].name,
                         PASSWORDS[i].name);
                    nopen(host, port);
                    nprintf(CVS_VERIF,root?root:CVSROOTS[USERNAMES[c].id].name,
                            user?user:USERNAMES[c].name, scramble(PASSWORDS[i].name) );
                    rbuf = flush_sock();
                    nclose();
                    if (strstr(rbuf, CVS_AUTH_FAILED))
                        info(BAD_TRIP, rbuf);
                    else if (strstr(rbuf, CVS_AUTH_SUCCESS))
                        {
                            info(GOOD_TRIP);
                            if (!root)
                                root = CVSROOTS[ USERNAMES[c].id ].name;
                            if (!user)
                                user = USERNAMES[c].name;
                            pass = PASSWORDS[i].name;
                            free(rbuf);
                            printf(SUCCESS_LOGON, user, pass, root);
                            return (1);
                        }
                    else
                        info(BAD_TRIP);
                    free(rbuf);
                }
            if (user)
                return (0);
        }
    return (0);
}
Exemple #24
0
int createP2mFile(FILE *fp, u8 *bin, u32 binlen, u32 *p2mlen)
{
	P2M_DIR *dir = newP2mDir(P2M_GAMENAME, P2M_ROOTNAME);

	if (dir == NULL) return -1;

	if (addP2mDirFile(dir, "icon.sys", icon_sys, sizeof(icon_sys)) < 0) return -2;
	if (addP2mDirFile(dir, "fcd.ico", fcd_ico, sizeof(fcd_ico)) < 0) return -2;
	if (addP2mDirFile(dir, P2M_FILENAME, bin, binlen) < 0) return -2;

	fwrite(P2M_FILE_ID, sizeof(char), strlen(P2M_FILE_ID), fp);
	scramble(dir);
	writeP2mDir(dir, fp);
	put_u32(0, fp); // No further dirs

	*p2mlen = dir->dirhdr->totalsize + 12;

	freeP2mDir(dir);

	return 0;
}
Exemple #25
0
uint32_t aprs_encode_image(uint8_t* message, mod_t mod, uint8_t *image, size_t size)
{
	ax25_t packet;
	packet.data = message;
	packet.max_size = 512; // TODO: replace 512 with real size
	packet.mod = mod;

	// Encode APRS header
	ax25_send_header(&packet, APRS_CALLSIGN, APRS_SSID, NULL);
	ax25_send_string(&packet, "{{I");

	// Encode image message
	for(uint16_t i=0; i<size; i++)
		ax25_send_byte(&packet, image[i]);

	// Send footer
	ax25_send_footer(&packet);
	nrzi_encode(&packet);
	scramble(&packet);

	return packet.size;
}
Exemple #26
0
int main(int argc, char *argv[])
{
  int opt = 0;

  if(argc > 1 && !strcmp(argv[1], "-d"))
    opt ++;
  printf("DC Binary Scrambler\n");
  if(argc != 3+opt)
    {
      /*fprintf(stderr, "Usage: %s [-d] from to\n", argv[0]);*/
      printf("Usage: %s [-d] from to\n", argv[0]);
      exit(1);
    }
  
  if(opt){
    descramble(argv[2], argv[3]);
	printf("\nDescrambling %s to ouptut file %s.\n", argv[2], argv[3]);
  }else{
    scramble(argv[1], argv[2]);
	printf("\nScrambling %s to ouptut file %s.\n", argv[1], argv[2]);
  }
  return 0;
}
Exemple #27
0
REQUEST\n"
#define REQUEST "Root %s\n"

void login(char *login, char *password, char *repo)
{
	char *buf, *ptr, reply[1024];
	char *rep, *rp;
	buf = (char *)malloc(1024);
	rep = (char *)malloc(512);

	ptr = buf;
	rp = rep;
	sprintf(ptr, LOGIN, login, scramble(password));
	sprintf(rp, REQUEST, repo);

	ptr = buf;

	xp_write(ptr); /* login request */
	xp_receive();
	xp_write(rp); /* root dir request */


}
Exemple #28
0
int
main( int argc, char **argv )
{
    int i;
    char *e, *m, biggie[256];

    char *cleartexts[5];
    cleartexts[0] = "first";
    cleartexts[1] = "the second";
    cleartexts[2] = "this is the third";
    cleartexts[3] = "$#% !!\\3";
    cleartexts[4] = biggie;

    /* Set up the most important test string: */
    /* Can't have a real ASCII zero in the string, because we want to
       use printf, so we substitute the character zero. */
    biggie[0] = '0';
    /* The rest of the string gets straight ascending ASCII. */
    for (i = 1; i < 256; i++)
	biggie[i] = i;

    /* Test all the strings. */
    for (i = 0; i < 5; i++)
    {
	printf ("clear%d: %s\n", i, cleartexts[i]);
	e = scramble (cleartexts[i]);
	printf ("scram%d: %s\n", i, e);
	m = descramble (e);
	free (e);
	printf ("clear%d: %s\n\n", i, m);
	free (m);
    }

    fflush (stdout);
    return 0;
}
Exemple #29
0
int main(void)
{
	const int N = 50;
	int i, cnt, action;
	char ch;
	Row data[N];
	Key key;
	FILE *file = fopen("input.txt", "r");

	if (file == NULL)
	{
		printf("Ошибка при открытии файла\n");

		return 0;
	}

	i = 0;

	while (i < N && fscanf(file, "%hd %hd", &data[i].key.a, &data[i].key.b) == 2)
	{
		fscanf(file, "%c", &ch);
		getRow(file, data[i].val, sizeof(data[i].val));

		i++;
	}

	fclose(file);

	cnt = i;

	do
	{
		printf("Меню\n");
		printf("1) Печать\n");
		printf("2) Двоичный поиск\n");
		printf("3) Сортировка\n");
		printf("4) Перемешивание\n");
		printf("5) Реверс\n");
		printf("6) Выход\n");
		printf("Выберите действие\n");
		scanf("%d", &action);

		switch (action)
		{
			case 1:
			{
				printTable(data, cnt);

				break;
			}

			case 2:
			{
				if (!isSorted(data, cnt))
					printf("Ошибка. Таблица не отсортирована\n");
				else
				{
					printf("Введите ключ: ");
					scanf("%hd %hd", &key.a, &key.b);

					i = binSearch(data, cnt, key);

					if (i > -1)
						printf("Найдена строка: %s\n", data[i].val);
					else
						printf("Строка с таким ключом не найдена\n");
				}

				break;
			}

			case 3:
			{
				sort(data, cnt);

				break;
			}

			case 4:
			{
				scramble(data, cnt);

				break;
			}

			case 5:
			{
				reverse(data, cnt);

				break;
			}

			case 6: break;

			default:
			{
				printf("Ошибка. Такого пункта меню не существует\n");

				break;
			}
		}
	}
	while (action != 6);

	return 0;
}
Exemple #30
0
inline QString unscramble64(QString in)
{
	return scramble(unbase64(in));
}