LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2009, 12:54 PM   #16
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231

If you are talking about portability:
Code:
 struct termios attr;
    static char password[MAX_STRING_LEN];
    int n=0;
    fputs(prompt, stderr);
    fflush(stderr);
	
    if (tcgetattr(STDIN_FILENO, &attr) != 0)
        return NULL;
    attr.c_lflag &= ~(ECHO);

    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
	    return NULL;
    while ((password[n] = getchar()) != '\n') {
        if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n] <= '~') {
            n++;
        } else {
            fprintf(stderr,"\n");
            fputs(prompt, stderr);
            fflush(stderr);
            n = 0;
        }
    }
 
    password[n] = '\0';
    printf("\n");
    if (n > (MAX_STRING_LEN - 1)) {
        password[MAX_STRING_LEN - 1] = '\0';
    }

    attr.c_lflag |= ECHO;
    tcsetattr(STDIN_FILENO, TCSANOW, &attr);
    
    char *pass;
    pass = (char*)malloc(strlen(password)+1);
    strcpy(pass, password);
    
    return pass;
That, is not portable.
Just use the built in getpass(), as I am basically positive terminios().
 
Old 12-17-2009, 01:06 PM   #17
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Rep: Reputation: 40
Smeeze, I'm not using the OP's routine, but am wondering about whether you should get the same encryption each time you run it on an identical block of data?
 
Old 12-17-2009, 02:00 PM   #18
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
if you use the same password as well, i would assume so.
 
Old 12-17-2009, 04:22 PM   #19
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by DiBosco View Post
Smeeze, I'm not using the OP's routine, but am wondering about whether you should get the same encryption each time you run it on an identical block of data?
That is only the case for ecb mode. See Block cipher modes of operation
 
Old 12-18-2009, 07:18 AM   #20
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Rep: Reputation: 40
Quote:
Originally Posted by ntubski View Post
That is only the case for ecb mode. See Block cipher modes of operation
Which xtea would appear to be. Do I understand correctly?
 
Old 12-18-2009, 11:36 AM   #21
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by DiBosco View Post
Which xtea would appear to be. Do I understand correctly?
If you meant "appear to be" a block cipher, then yes. Block ciphers can be used in ecb mode in which case key+data gives the same cipher-text every time. If you use cbc mode with xtea, for instance, then the cipher-text resulting from key+data depends on all the data that was encrypted in previous data blocks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Based "Tea Timer" Reminder System for Ubuntu Jaffa8 Linux - Newbie 2 02-08-2008 11:03 AM
Scripting the tea making process... pwc101 General 9 05-01-2007 06:58 AM
LXer: Open source software helps online tea vendor LXer Syndicated Linux News 0 12-31-2005 12:31 PM
spilled tea on my keyboard and need to disable it... kenkajoto Linux - Hardware 10 12-04-2004 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration