Thread: text length & file encryption problems

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    text length & file encryption problems

    hey, if i want to encrypt some text using one of the various methods, and the text is larger than 1024 bytes... how do i get the next 1024 bytes?

    also, i discovered the EncryptFile() function, but what exactly does it do? does it just like "lock" files so that the current user has permissions for them and if another user on the system tries to access the file, they won't be able to?

    also, i'm getting this error
    undefined reference to `AES256_BytesMode@28'
    for this code:
    Code:
        unsigned char key[32];
    	unsigned char plain[1024];
    	unsigned char cipher[1024];
    	long keybits;
    	unsigned char iv[16];
    	char *modes[] = { "ECB", "CBC" }, *buf, *length, *res;
    	int i, j, n, im, len;
    	long result;
    	HWND hwndEdit = GetDlgItem(hwnd,IDC_CHILD_EDIT);
    
    	srand((unsigned)time(NULL));
    
    	for (i = 0; i < 10; i++)
    	{
    		/* Set key size */
    		keybits = 256;
    
    		/* Create a random key */
    		for (j = 0; j < keybits / 8; j++)
    			key[j] = rand() & 0xFF;
    
    		/* and a random IV */
    		for (j = 0; j < sizeof(iv); j++)
    			iv[j] = rand() & 0xFF;
    
    		/* Select a mode index: 0 or 1 */
    		im = rand() & 0x01;
    
    		/* Create some 'random' plaintext up to 1024 bytes long */
    		/* in a multiple of block size */
    		n = ((rand() % 16) + 1) * 16; 
    	
            len = GetWindowTextLength(hwndEdit);	
            itoa(len, length, 5);
            MessageBox(hwnd, length, "Length of text:", MB_OK | MB_ICONINFORMATION);
            if (len <= 0) { MessageBox(hwnd, "There is no text to encrypt.", "Error.", MB_OK | MB_ICONERROR); return FALSE; }
            buf = (char*)malloc(len + 1);
            GetDlgItemText(hwnd, IDC_CHILD_EDIT, buf, len);
    
    		for (j = 0; j < n; j++)
    			plain[j] = buf[j];
    
    		/* Encrypt it into ciphertext */
    result = AES256_BytesMode(cipher, plain, n, key, ENCRYPT, modes[im], iv);
    see anything wrong?
    i can post more complete code if need be.

    thanks
    Last edited by willc0de4food; 06-29-2005 at 05:09 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Sort by Character Length, Text File
    By glj12 in forum C Programming
    Replies: 12
    Last Post: 01-23-2008, 06:04 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM