terça-feira, 31 de maio de 2016

Codificador e decodificador de arquivos

Pode ser que você utiliza um computador compartilhado com outros usuários, numa
mesma rede ou conta, e as vêzes deseja escrever algo que ninguém possa ler.
Talvez você possua senhas complexas com caracteres maiúsculos com minúsculos e
números onde o copiar e colar é preciso para logar.
A minha sugestão é que você venha codificar suas senhas ou arquivos utilizando
o meu programa apresentado aqui neste post.
Breve descrição do funcionamento:
As ações originais de operações bit a bit são:
testar, atribuir ou deslocar os bits vinculados a caracteres, palavras, ou números
inteiros, que são respectivamente os tipos char e int da linguagem C, incluindo
as variantes destes tipos.
O futuro programador já deve ficar ciente que operações bit a bit não podem ser usadas
em tipo float ou double, long double, void ou qualquer outro tipo mais complexos.
Más estou me referindo ao único que é usado neste programa que é o " ~ ", entre
as aspas na nossa língua portuguêsa, chamamos de "til", porém na linguagem C
chamamos de complemento de um.
Este operador inverte o estado de variáveis específicas em operações conjuntas,
onde os zeros passarão a ser um, e os uns passarão a ser zeros.
Como nossa máquina só entende 0 e 1,tal qual num circuito digital, não foi muito
difícil criar este programa usando como componente principal este importante
operador do C, e os leitores devem achar isto muito interessante e pode ser tudo
o que você procurava em se tratando de um exemplo claro e funcional.
O programa começa mostrando um belo e organizado menu de seis opções usando
comandos ifs para interação com o usuário.

Veja abaixo imagens do programa em execução:








Veja abaixo o código do programa:

/*
Éder Costa   
Humberto Gomes
Dijalma Lacerda
Caroline Silva
Igor Gonçalves
Bruna Carla 
Fábio Quadros
Geany Barros 
Jaqueline Vega
Ana Célia
*/

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int Menu_Arq ( );
void got_color ( int tam_lin_ini, int tam_lin_fim, int tam_ini_col,
         int tam_fim_col, int a, int b ) {
     int i, c;
     if ( a >= 1 && a <= 16 ) {
         textcolor ( a );
     }
     if ( b >= 1 && b <= 16 ) {
         textbackground ( b );
     }
     for ( i = tam_lin_ini; i < tam_lin_fim; i++ ) {
         for ( c = tam_ini_col; c < tam_fim_col; c++ ) {
              gotoxy ( c, i );
              printf ( " " );
         }
     }
}
int Abre_Arq ( ) {
     textcolor ( LIGHTRED );
     gotoxy ( 23, 3 );
     printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 28, 5 );
     printf ( "Abaixo a leitura do arquivo" );
     char nome [ 11 ] [ 17 ] = { 0 };
     int i = 0;
     FILE *arq;
     if ( ( arq = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
              "Arquivos\\Nomes.txt", "r" ) ) == NULL ) {
         printf ( "Houve um erro na abertura do arquivo" );
         getche ( );
         exit ( 1 );
     }
     while ( feof ( arq ) == 0 ) {
         fgets ( nome [ i ], 20, arq );
         ++i;
     }
     fclose ( arq );
     textcolor ( BLACK );
     for ( i = 0; i < 10; i++ ) {
         gotoxy ( 35, i + 7 );
         printf ( "%s", nome [ i ] );
     }
     Sleep ( 1800 );
     textcolor ( LIGHTRED );
     gotoxy ( 30, 23 );
     printf ( "PRESSIONE QUALQUER TECLA" );
     getche ( );
     return Menu_Arq ( );
}
int Abre_Arq_Cod ( ) {
     char nome [ 11 ] [ 17 ] = { 0 };
     textcolor ( LIGHTRED );
     gotoxy ( 23, 3 );
     printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 23, 5 );
     printf ( "Abaixo a leitura do arquivo codificado" );
     int i = 0;
     FILE *arq;
     if ( ( arq = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
              "Arquivos\\Nomes II.txt", "r" ) ) == NULL ) {
         printf ( "Houve um erro na abertura do arquivo" );
         getche ( );
         exit ( 1 );
     }
     while ( feof ( arq ) == 0 ) {
         fgets ( nome [ i ], 100, arq );
         ++i;
     }
     fclose ( arq );
     textcolor ( BLACK );
     for ( i = 0; i < 2; i++ ) {
         gotoxy ( 11, i + 7 );
         printf ( "%s", nome [ i ] );
     }
     fclose ( arq );
     Sleep ( 1800 );
     textcolor ( LIGHTRED );
     gotoxy ( 30, 23 );
     printf ( "PRESSIONE QUALQUER TECLA" );
     getche ( );
     return Menu_Arq ( );
     return 0;
}
int Abre_Arq_Dec ( ) {
     textcolor ( LIGHTRED );
     gotoxy ( 23, 3 );
     printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 19, 5 );
     printf ( "Abaixo a leitura do arquivo que foi decodificado" );
     char nome [ 11 ] [ 17 ] = { 0 };
     int i = 0;
     FILE *arq;
     if ( ( arq = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
              "Arquivos\\Nomes III.txt", "r" ) ) == NULL ) {
         printf ( "Houve um erro na abertura do arquivo" );
         getche ( );
         exit ( 1 );
     }
     while ( feof ( arq ) == 0 ) {
         fgets ( nome [ i ], 20, arq );
         ++i;
     }
     fclose ( arq );
     textcolor ( BLACK );
     for ( i = 0; i < 10; i++ ) {
         gotoxy ( 35, i + 7 );
         printf ( "%s", nome [ i ] );
     }
     Sleep ( 1800 );
     textcolor ( LIGHTRED );
     gotoxy ( 30, 23 );
     printf ( "PRESSIONE QUALQUER TECLA" );
     getche ( );
     return Menu_Arq ( );
}
int Menu_Arq ( ) {
     system ( "Color E9" );
     FILE *arq;
     FILE *pf;
     char ct, sig, flh;
     int mov;
     int j;
     do {
         got_color ( 2, 25, 3, 79, 2, 15 );
         textcolor ( LIGHTRED );
         gotoxy ( 23, 3 );
         printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
         textcolor ( LIGHTMAGENTA );
         gotoxy ( 29, 5 );
         printf ( "ESCOLHA UMA OPCÃO ABAIXO " );
         textcolor ( LIGHTBLUE );
         gotoxy ( 15, 7 );
         printf ( "1 - Abrir o arquivo" );
         gotoxy ( 15, 8 );
         printf ( "2 - Codificar o arquivo" );
         gotoxy ( 15, 9 );
         printf ( "3 - Decodificar o arquivo" );
         gotoxy ( 15, 10 );
         printf ( "4 - Abrir o arquivo codificado" );
         gotoxy ( 15, 11 );
         printf ( "5 - Abrir o arquivo decodificado" );
         gotoxy ( 15, 12 );
         printf ( "6 - Sair" );
         textcolor ( LIGHTRED );
         gotoxy ( 15, 14 );
         scanf ( "%d", &j );
         fflush ( stdin );
         if ( j == 1 ) {
              clrscr ( );
              system ( "Color D7" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              Abre_Arq ( );
         }
         if ( j == 2 ) {
              clrscr ( );
              system ( "Color A9" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              textcolor ( LIGHTRED );
              gotoxy ( 23, 3 );
              printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
              textcolor ( LIGHTBLUE );
              gotoxy ( 26, 5 );
              printf ( "O arquivo está sendo codificado ... " );
              if ( ( arq = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
                        "Arquivos\\Nomes.txt", "r" ) ) == NULL ) {
                   printf ( "Houve um erro na abertura do arquivo" );
                   getche ( );
                   exit ( 0 );
              }
              if ( ( pf = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
                        "Arquivos\\Nomes II.txt", "w" ) ) == NULL ) {
                   printf ( "Houve um erro na criação do arquivo" );
                   getche ( );
                   exit ( 0 );
              }
              mov = 3;
              while ( ( ct = getc ( arq ) ) != EOF ) {
                   sig = ~ct;
                   flh = sig + mov;
                   putc ( flh, pf );
              }
              Sleep ( 2800 );
              textcolor ( LIGHTBLUE );
              gotoxy ( 23, 21 );
              printf ( "O arquivo foi codificado com sucesso" );
              textcolor ( LIGHTRED );
              gotoxy ( 30, 23 );
              printf ( "PRESSIONE QUALQUER TECLA" );
              getche ( );
              system ( "Color E9" );
              fclose ( arq );
              fclose ( pf );
         }
         if ( j == 3 ) {
              clrscr ( );
              system ( "Color B5" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              textcolor ( LIGHTRED );
              gotoxy ( 23, 3 );
              printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
              textcolor ( LIGHTBLUE );
              gotoxy ( 25, 5 );
              printf ( "O arquivo está sendo decodificado ... " );
              if ( ( arq = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
                        "Arquivos\\Nomes II.txt", "r" ) ) == NULL ) {
                   printf ( "Houve um erro na abertura do arquivo" );
                   getche ( );
                   exit ( 1 );
              }
              if ( ( pf = fopen ( "C:\\Users\\SAMUEL 64SP1\\Desktop\\"
                        "Arquivos\\Nomes III.txt", "w" ) ) == NULL ) {
                   printf ( "Houve um erro na criação do arquivo" );
                   getche ( );
                   exit ( 1 );
              }
              mov = 3;
              while ( ( ct = getc ( arq ) ) != EOF ) {
                   flh = ct - mov;
                   sig = ~flh;
                   putc ( sig, pf );
              }
              Sleep ( 2800 );
              textcolor ( LIGHTBLUE );
              gotoxy ( 23, 21 );
              printf ( "O arquivo foi decodificado com sucesso" );
              textcolor ( LIGHTRED );
              gotoxy ( 30, 23 );
              printf ( "PRESSIONE QUALQUER TECLA" );
              getche ( );
              system ( "Color E9" );
              fclose ( arq );
              fclose ( pf );
         }
         if ( j == 4 ) {
              clrscr ( );
              system ( "Color C6" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              Abre_Arq_Cod ( );
         }
         if ( j == 5 ) {
              clrscr ( );
              system ( "Color 10" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              Abre_Arq_Dec ( );
         }
         if ( j == 6 ) {
              clrscr ( );
              system ( "Color 09" );
              got_color ( 2, 25, 3, 79, 2, 15 );
              textcolor ( LIGHTRED );
              gotoxy ( 23, 3 );
              printf ( "CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
              Sleep ( 1800 );
              textbackground ( WHITE );
              textcolor ( LIGHTBLUE );
              gotoxy ( 21, 19 );
              printf ( "Por: " );
              textcolor ( LIGHTMAGENTA );
              printf ( "Samuel Lima" );
              textcolor ( BLACK );
              gotoxy ( 21, 20 );
              printf ( "sa_sp10@hotmail.com" );
              Sleep ( 1800 );
              textcolor ( LIGHTRED );
              gotoxy ( 36, 23 );
              printf ( "MUITO OBRIGADO" );
              getche ( );
              exit ( 0 );
         }
         if ( j < 0 || j > 7 ) {
              textcolor ( LIGHTRED );
              gotoxy ( 37, 17 );
              printf ( "\aOpção errada" );
              Sleep ( 1800 );
         }
     } while ( 1 );
     return 0;
}
int main ( ) {
     system ( "title CODIFICADOR E DECODIFICADOR DE ARQUIVOS" );
     Menu_Arq ( );
     return ( 0 );
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.