Sponsored Content
Top Forums Shell Programming and Scripting Encript Timestamp with blowfish Post 302463841 by DGPickett on Monday 18th of October 2010 02:46:47 PM
Old 10-18-2010
See man crypt for 1 & 2.
The 'net is full of base 64 encode/decode tools. I wrote my own C decoder:

Code:
$ cat mysrc/base64dec.c

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

static int i, o ;
static int ostate = 0 ;

static void p_putchar( int c ){
//fprintf(stderr,"p_putchar(%d=%c)\n",c,c);
  if ( EOF == putchar( c )){
    if ( ferror( stdout )){
      perror( "base64dec: stdout" );
      exit( 1 );
     }

    exit( 0 );
   }
 }

static void newbits( int b ){
//fprintf(stderr,"newbits(%d), ostate %d, o %d, i %d=%c\n",b,ostate,o,i,i);
  switch ( ostate ){
   case 0:
    o = b ;
    ostate = 6 ;
    return ;
   case 6:
    p_putchar( ( o << 2 ) | ( b >> 4 ) );
    o = b & 15 ;
    ostate = 4 ;
    return ;
   case 4:
    p_putchar( ( o << 4 ) | ( b >> 2 ));
    o = b & 3 ;
    ostate = 2 ;
    return ;
   default:
    p_putchar( ( o << 6 ) | b );
    ostate = 0 ;
    return ;
   }
 }

int main( int argc, char **argv ){

  int v = 0 ;

  if ( argc > 1
    && !strcmp( argv[1], "-v" )){
      v = 1 ;
   }

  while ( EOF != ( i = getchar())){
    if ( i > 'z' ){
      continue ;
     }

    if ( i < '+' ){
      continue ;
     }

    if ( i > 'Z' ){
      if ( i >= 'a' ){
        newbits( i - 'a' + 26 );
       }
      continue ;
     }

    if ( i >= 'A' ){
      newbits( i - 'A' );
      continue ;
     }   

    if ( i > '9' ){
      continue ;
     }   

    if ( i >= '0' ){
      newbits( i - '0' + 52 );
      continue ;
     }   

    if ( i == '/' ){
      newbits( 63 );
      continue ;
     }   

    if ( i == '+' ){
      newbits( 62 );
     }   
   } /* end while getchar */

  if ( ferror( stdin )){
    perror( "base64dec: stdin" );
    exit( 1 );
   }

  if ( ostate && v ){
    fprintf( stderr,
"\nbase64dec: Warning: %d bits =%d left at EOF.\n",
      ostate, o );
    exit( 2 );
   }

  exit( 0 );
 }

This User Gave Thanks to DGPickett For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

samba questions (password conversion to blowfish and is it wise to sync the useraccou

i stumbled upon something that gave some nice instructions on how to convert FreeBSD passwords from md5 to blowfish. it was simple and straight forward and it worked. i'm running samba on the machine. now i know the tutorial i was following had something where a user's samba and machine... (1 Reply)
Discussion started by: xyyz
1 Replies

2. Shell Programming and Scripting

how to encript password in .netrc file

hi, I am using .netrc file WITH OUT encripting the password Code in .netrc file: ------------------- machine $SYSTEM NAME login FTFOA001 password 1Q2W3E4R how to encript password in .netrc file.(i should not use "1Q2W3E4R" as password). after encripting i should able to connect with... (1 Reply)
Discussion started by: getgopu25
1 Replies

3. Shell Programming and Scripting

how to encript a shell

I have a unix shell, there is a way to encript the whole shell, and be able to run the encripted shell, so I can give my client the encripted shell, and he can't see the code I wrote? (6 Replies)
Discussion started by: pedro_lezaeta
6 Replies

4. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

5. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

6. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

7. Homework & Coursework Questions

[SOLVED] blowfish algorithm: encrypting the p-array.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to encrypt the p-array. The first element will print correctly once returned from my encrypt... (2 Replies)
Discussion started by: robin_simple
2 Replies

8. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

9. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

10. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies
GETS(3) 						     Linux Programmer's Manual							   GETS(3)

NAME
fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings SYNOPSIS
#include <stdio.h> int fgetc(FILE *stream); char *fgets(char *s, int size, FILE *stream); int getc(FILE *stream); int getchar(void); char *gets(char *s); int ungetc(int c, FILE *stream); DESCRIPTION
fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once. getchar() is equivalent to getc(stdin). gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with ''. No check for buffer overrun is performed (see BUGS below). fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '' is stored after the last character in the buffer. ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed - back characters will be returned in reverse order; only one pushback is guaranteed. Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream. For non-locking counterparts, see unlocked_stdio(3). RETURN VALUE
fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error. gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read. ungetc() returns c on success, or EOF on error. CONFORMING TO
ANSI - C, POSIX.1 BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead. It is not advisable to mix calls to input functions from the stdio library with low - level calls to read() for the file descriptor associ- ated with the input stream; the results will be undefined and very probably not what you want. SEE ALSO
read(2), write(2), ferror(3), fopen(3), fread(3), fseek(3), puts(3), scanf(3), unlocked_stdio(3) GNU
1993-04-04 GETS(3)
All times are GMT -4. The time now is 06:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy