Skocz do zawartości
linda34234

szyfrowanie pliku txt w borland c++

Rekomendowane odpowiedzi

czy ktos potrafi sie tym zajac?
posiadam skrypty szyfrowania np rot13 czy atbash_c
jak to przepisac na borlanda?
moge zaplacic za pomoc

zrobilem aplikacje, potrzebuje podpiac kod szyfrowania pliku txt pod przyckiski
beda 3 algorytmy szyfrowania pliku txt

projekt do wgladu
moj email lukgro1991@wp.pl

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

jak to przepisac na borlanda?

zrobilem aplikacje, potrzebuje podpiac kod szyfrowania pliku txt pod przyckiski

wiesz, to się razem kupy nie klei, bo jak można napisac aplikacje z przyciskami nie znając podstaw c/c++?

Zebys jeszcze napisal w czym napisales te aplikacje z klawiszami....

Edytowane przez _KaszpiR_

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

W klasie AnsiString nie ma metody t_str.

 

Spróbuj zmienić zmienne typu AnsiString na UnicodeString.

 

 

http://stackoverflow.com/questions/12558635/convert-a-unicode-string-to-a-string

 

Inna sprawa ze t_str jest już metodą niezalecaną, powinno się stosować c_str

 

http://docwiki.embarcadero.com/Libraries/XE2/en/System.UnicodeString.t_str

Edytowane przez _KaszpiR_

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

Chodziło o to, że t_str jest stare. Używa się teraz c_str.

Chciałbym zrozumieć ten kod:

  //================================================================ ENTER TEXT
void enter (int text) {
switch (text) {
case CLEAR: {
    Main->MemoClearText->Font->Color = clRed;
    char* clearText =
     new char[Main->MemoClearText->Text.Length() + 1];
    strcpy(clearText, Main->MemoClearText->Text.c_str());
    clearLength = StrLen(clearText);
Main->MemoClearNumber->Text = "";
for (int i = 0; i < clearLength; i++) {
      Main->EditClearTextLength->Text = clearLength;
      // convert ASCII numbers to modified numerical alphabet
      clearNumber = clearText;  // convert to values
      if (clearNumber > 93) clearNumber--; // elim up arrow
      clearNumber -= 32;  // elim control chars
      if (i == 0) Form1->MemoClearNumber->Text =
         Form1->MemoClearNumber->Text + " " + clearNumber;
      else Form1->MemoClearNumber->Text =
         Form1->MemoClearNumber->Text + ", " + clearNumber;
    }
break;
}
case KEY: {
    Form1->MemoKeyText->Font->Color = clRed;
    char* keyText =
     new char[Form1->MemoKeyText->Text.Length() + 1];
    strcpy(keyText, Form1->MemoKeyText->Text.t_str());
keyLength = StrLen(keyText);
    Form1->MemoKeyNumber->Text = "";
for (int i = 0; i < keyLength; i++) {
      Form1->EditKeyTextLength->Text = keyLength;
      // convert ASCII numbers to modified numerical alphabet
      keyNumber = keyText;  // convert to values
      if (keyNumber > 93) keyNumber--; // elim up arrow
      keyNumber -= 32;  // elim control chars
      if (i == 0) Form1->MemoKeyNumber->Text =
      Form1->MemoKeyNumber->Text + " " + keyNumber;
      else Form1->MemoKeyNumber->Text =
      Form1->MemoKeyNumber->Text + ", " + keyNumber;
    }
break;
  }
  case CIPHER: {
Form1->MemoCipherText->Font->Color = clRed;
    char* cipherText =
     new char[Form1->MemoCipherText->Text.Length() + 1];
    strcpy(cipherText, Form1->MemoCipherText->Text.t_str());
cipherLength = StrLen(cipherText);
Form1->MemoCipherNumber->Text = "";
    for (int i = 0; i < cipherLength; i++) {
Form1->EditCipherTextLength->Text = cipherLength;
      // convert ASCII numbers to modified numerical alphabet
      cipherNumber = cipherText;  // convert to values
      if (cipherNumber > 93) cipherNumber--; // elim up arrow
      cipherNumber -= 32;  // elim control chars
      if (i == 0) Form1->MemoCipherNumber->Text =
      Form1->MemoCipherNumber->Text + " " + cipherNumber;
      else Form1->MemoCipherNumber->Text =
      Form1->MemoCipherNumber->Text + ", " + cipherNumber;
    }
    break;
}
}
}


Z tego co widzę jest pole klucza, pole do wprowadzenia tekstu do szyfrowania i pole wyniku. Zgadza się?

Dalej - jest problem ze zmiennymi. Nie bardzo rozumiem dlaczego pojawia się błąd przy MemoClearNumber - co to właściwie jest? MemoCipherText to rozumiem jest pole do wprowadzenia pierwszej treści?

To jest algorytm https://web.duke.edu/isis/gessler/borland/vigenere94.txt.

Płacę za pomoc...

Płacę za pomoc...

Płacę za pomoc...

#define CLEAR 0
#define KEY 1
#define CIPHER 2


char c;
char *str;
int i;
int clearLength;
int keyLength;
int cipherLength;
int dec;
int clearArray[1000];
int keyArray[1000];
int cipherArray[1000];



// this sets up bitmap graphics variables to hold the pictures.
Graphics::TBitmap* pixPlain = new Graphics::TBitmap();
Graphics::TBitmap* pixKey = new Graphics::TBitmap();
Graphics::TBitmap* pixCrypto = new Graphics::TBitmap();
RGBTRIPLE* t;

BYTE myByte;

AnsiString plainText, KeyText, cryptoText;

// cycle counts the steps in a 256 color circuit
int cycle = 0;
// step counts the steps in the alter .bmp loop
int step;
bool stop = false;
int pixel = 0;
int row, column;
int times;
 //
  //   FUNCTIONS
//===========================================================================

//================================================================ ENTER MEMO
void enter (int text) {
switch (text) {
  case CLEAR: {
Main->MemoClear->Font->Color = clBlack;
char* clearText = new char[ Main->MemoClear->Text.Length() + 1 ];
strcpy( clearText, Main->MemoClear->Text.c_str() );
clearLength = StrLen(clearText);
Main->MemoClearASCII->Text = "";
for (int i = 0; i < clearLength; i++) {
Main->EditClearLength->Text = clearLength;
char x = clearText;
Main->MemoClearASCII->Text =
  Form1->MemoClearASCII->Text + " " + IntToStr(x - 31);
clearArray = clearText - 31;
}
break;
  }
  case KEY: {
Main->MemoKey->Font->Color = clBlack;
char* keyText = new char[ Main->MemoKey->Text.Length() + 1 ];
strcpy( keyText, Form1->MemoKey->Text.c_str() );
keyLength = StrLen(keyText);
Main->MemoKeyASCII->Text = "";
for (int i = 0; i < keyLength; i++) {
Main->EditKeyLength->Text = keyLength;
char x = keyText;
Main->MemoKeyASCII->Text =
  Main->MemoKeyASCII->Text + " " + IntToStr(x - 31);
keyArray = keyText - 31;
}
break;
  }
  case CIPHER: {
Main->MemoCipher->Font->Color = clBlack;
char* cipherText
  = new char[ Main->MemoCipher->Text.Length() + 1 ];




Jest problem z EditClearLength? Dlaczego nie działa? Czy jest jakaś inna wersja tego polecenia? Borland 6 C++!

[C++ Error] Unit1.cpp(320): E2090 Qualifier 'Main' is not a class or namespace name

?

Jak wczytać obraz z folderu do Image po wybraniu przycisku?

Teraz doszedłem do tego, ale nie działa ogólnie jak trzeba. Muszę to przebudować.

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

[Linker Error] Unresolved external '__fastcall TMain::OpenPictureDialogPlainClick(System::TObject *)' referenced from C:USERSTWIERDZA GIERDESKTOPPRIVYCRYPT-WIN32-SRC2_5PRIVYCRYPTUNIT1.OBJ

A to co?

W tym programie linkuje czasami klasy i trzeba je wstawić drugi raz, wtedy błąd znika. Kasowanie pliku .obj nie pomaga.

Trzeba mi jeszcze jakiś algorytm szyfrujący pod Borlanda. Ktoś może się tym bawił? Potrafi coś zrobić, niech się odzywa. Perspektywa długiej współpracy.

void Crypt2(char *inp, DWORD inplen, char* key)
{
  //we will consider size of sbox 256 bytes
  //(extra byte are only to prevent any mishep just in case)
  char Sbox[257], Sbox2[257];
  unsigned long i, j, t, x;

  char temp , k;
  i = j = k = t =  x = 0;
  temp = 0;

  //always initialize the arrays with zero
  ZeroMemory(Sbox, sizeof(Sbox));
  ZeroMemory(Sbox2, sizeof(Sbox2));

  //initialize sbox i
  for(i = 0; i < 256U; i++)
  {
  Sbox = (char)i;
  }

  j = 0;

  //initialize the sbox2 with user key
  for(i = 0; i < 256U ; i++)
  {
  if(j == strlen(key))
  {
  j = 0;
  }
  Sbox2 = key[j++];
  }


  j = 0 ; //Initialize j
  //scramble sbox1 with sbox2
  for(i = 0; i < 256; i++)
  {
  j = (j + (unsigned long) Sbox + (unsigned long) Sbox2) % 256U ;
  temp =  Sbox;
  Sbox = Sbox[j];
  Sbox[j] =  temp;
  }

  i = j = 0;
  for(x = 0; x < inplen; x++)
  {
  //increment i
  i = (i + 1U) % 256U;
  //increment j
  j = (j + (unsigned long) Sbox) % 256U;

  //Scramble SBox #1 further so encryption routine will
  //will repeat itself at great interval
  temp = Sbox;
  Sbox = Sbox[j] ;
  Sbox[j] = temp;

  //Get ready to create pseudo random  byte for encryption key
  t = ((unsigned long) Sbox + (unsigned long) Sbox[j]) %  256U ;

  //get the random byte
  k = Sbox[t];

  //xor with the data and done
  inp[x] = (inp[x] ^ k);

  //poinformuj o postępie
  if( x & 0x0000FFFF )  //ogranicz częstość aktualizacji informacji o postępie
  {
  Application->ProcessMessages();  //pozwól na przesuwanie okna itp.
   Main->CGauge2->Progress = 100 * (float)x/(float)lSize;
  Main->Update();
  }
  }
  Main->CGauge2->Progress = 100;
}

Może jakaś wariacja na ten temat? Co tu zmienić, aby był lepszy?

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

#define CLEAR 0
#define KEY 1
#define CIPHER 2

char c; //?
char *str; //?
int i;
int clearLength;
int keyLength;
int cipherLength;
int dec;
// these hold the modified ASCII alphabet
// modified from ASCII by eliminating control and arrow characters.
int clearArray[1000];
int keyArray[1000];
int cipherArray[1000];
int clearNumber[1000], keyNumber[1000], cipherNumber[1000];

int mod = 94;


void enter (int text) {
switch (text) {
case CLEAR: {
Main->MemoClearText->Font->Color = clRed;
char* clearText =
new char[Main->MemoClearText->Text.Length() + 1];
strcpy(clearText, Main->MemoClearText->Text.c_str());
clearLength = StrLen(clearText);
// Main->MemoClearNumber->Text = "";
for (int i = 0; i < clearLength; i++) {
// Main->EditClearTextLength->Text = clearLength;
// convert ASCII numbers to modified numerical alphabet
clearNumber = clearText; // convert to values
if (clearNumber > 93) clearNumber--; // elim up arrow
clearNumber -= 32; // elim control chars
// if (i == 0) Main->MemoClearNumber->Text =
// Form1->MemoClearNumber->Text + " " + clearNumber;
// else Main->MemoClearNumber->Text =
// Main->MemoClearNumber->Text + ", " + clearNumber;
}
break;
}
case KEY: {
Main->MemoKeyText->Font->Color = clRed;
char* keyText =
new char[Main->MemoKeyText->Text.Length() + 1];
strcpy(keyText, Main->MemoKeyText->Text.c_str());
keyLength = StrLen(keyText);
// Main->MemoKeyNumber->Text = "";
for (int i = 0; i < keyLength; i++) {
// convert ASCII numbers to numerical alphabet
// Main->EditKeyTextLength->Text = keyLength;
keyNumber = keyText; // convert to values
if (keyNumber > 93) keyNumber--; // elim up arrow
keyNumber -= 32; // elim control chars
// if (i == 0) Form1->MemoKeyNumber->Text =
// Main->MemoKeyNumber->Text + " " + keyNumber;
// else Main->MemoKeyNumber->Text =
// Maimodifiedn->MemoKeyNumber->Text + ", " + keyNumber;
}
break;
}
case CIPHER: {
// Main->MemoCipherText->Font->Color = clRed;
char* cipherText =
new char[Main->MemoCipherText->Text.Length() + 1];
strcpy(cipherText, Main->MemoCipherText->Text.c_str());
cipherLength = StrLen(cipherText);
// Main->MemoCipherNumber->Text = "";
for (int i = 0; i < cipherLength; i++) {
// Main->EditCipherTextLength->Text = cipherLength;
// convert ASCII numbers to modified numerical alphabet
cipherNumber = cipherText; // convert to values
if (cipherNumber > 93) cipherNumber--; // elim up arrow
cipherNumber -= 32; // elim control chars
// if (i == 0) Main->MemoCipherNumber->Text =
// Main->MemoCipherNumber->Text + " " + cipherNumber;
// else Main->MemoCipherNumber->Text =
// Main->MemoCipherNumber->Text + ", " + cipherNumber;
}
break;
}
}
}

//============================================================== EXTRACT TEXT
void extract (int text) {
switch (text) {
case CLEAR: {
Main->MemoClearText->Font->Color = clBlue;
if (cipherLength <= keyLength) {
Main->MemoClearText->Text = "";
// Main->MemoClearNumber->Text = "";
for (int i = 0; i < cipherLength; i++) {
clearNumber = cipherNumber - keyNumber;
if (clearNumber > mod) clearNumber -= mod;
if (clearNumber < 0) clearNumber += mod;
// if (i == 0) Main->MemoClearNumber->Text
// = Main->MemoClearNumber->Text
// + " " + (clearNumber);
// else Main->MemoClearNumber->Text
// = Main->MemoClearNumber->Text
// + ", " + (clearNumber);
// convert to ASCII
clearNumber += 32;
//if (clearNumber > 61) clearNumber++;
if (clearNumber > 93) clearNumber++;
if (clearNumber > 126) clearNumber = 32;
Main->MemoClearText->Text
= Main->MemoClearText->Text + char(clearNumber);
}
}
else Main->MemoClearText->Text = "Key Length Too Short";
break;
}
case KEY: {
Main->MemoKeyText->Font->Color = clBlue;
if (clearLength == cipherLength) {
Main->MemoKeyText->Text = "";
// Main->MemoKeyNumber->Text = "";
for (int i = 0; i < cipherLength; i++) {
keyNumber = cipherNumber - clearNumber;
if (keyNumber > mod) keyNumber -= mod;
if (keyNumber < 0) keyNumber += mod;
// if (i == 0) Main->MemoKeyNumber->Text
// = Main->MemoKeyNumber->Text
// + " " + (keyNumber);
// else Main->MemoKeyNumber->Text
// = Main->MemoKeyNumber->Text
// + ", " + (keyNumber);
// convert to ASCII
keyNumber += 32;
//if (keyNumber > 61) keyNumber++;
if (keyNumber > 93) keyNumber++;
if (keyNumber > 126) keyNumber = 32;
Main->MemoKeyText->Text
= Main->MemoKeyText->Text + char(keyNumber);
}
}
else Main->MemoKeyText->Text = "Clear and Cipher Lengths Unequal";
break;
}
case CIPHER: {
// Main->MemoCipherText->Font->Color = clBlue;
if (clearLength <= keyLength) {
Main->MemoCipherText->Text = "";
// Main->MemoCipherNumber->Text = "";
for (int i = 0; i < clearLength; i++) {
cipherNumber = clearNumber + keyNumber;
if (cipherNumber > mod) cipherNumber -= mod;
if (cipherNumber < 0) cipherNumber += mod;
// if (i == 0) Form1->MemoCipherNumber->Text
// = Form1->MemoCipherNumber->Text
// + " " + (cipherNumber);
// else Main->MemoCipherNumber->Text
// = Main->MemoCipherNumber->Text
// + ", " + (cipherNumber);
// convert to ASCII
cipherNumber += 32;
//if (cipherNumber > 61) cipherNumber++;
if (cipherNumber > 93) cipherNumber++;
if (cipherNumber > 126) cipherNumber = 32;
// Main->MemoCipherText->Text
// = Main->MemoCipherText->Text + char(cipherNumber);

}
}
else Main->MemoKeyText->Text = "Key Length Too Short";
break;
}
}
}
void Crypt2(char *inp, DWORD inplen, char* key)
{


enter(CLEAR);
enter(KEY);
extract(CIPHER);

//poinformuj o postępie
// if( x & 0x0000FFFF ) //ogranicz częstość aktualizacji informacji o postępie
// {
Application->ProcessMessages(); //pozwól na przesuwanie okna itp.
// Main->CGauge2->Progress = 100 * (float)x/(float)lSize;
Main->Update();
// }
}
// Main->CGauge2->Progress = 100;
//}

void Crypt3(char *inp, DWORD inplen, char* key)
{

enter(CIPHER);
enter(KEY);
extract(CLEAR);

//poinformuj o postępie
// if( x & 0x0000FFFF ) //ogranicz częstość aktualizacji informacji o postępie
{
Application->ProcessMessages(); //pozwól na przesuwanie okna itp.
// Main->CGauge2->Progress = 100 * (float)x/(float)lSize;
Main->Update();
}
}
//Main->CGauge2->Progress = 100;
//}

void __fastcall TMain::ClearClick(TObject *Sender)
{
Memo->Clear();
}


void __fastcall TMain::btnOpen2Click(TObject *Sender)
{
btnOpen2->Enabled = false;
//CGauge2->Progress = 0;
if(OpenDialog2->Execute())
{
FILE *pFileIn = fopen(OpenDialog2->FileName.c_str(), "rb");
if(!pFileIn)
{
Application->MessageBox("Problem z otwieraniem pliku!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
btnOpen2->Enabled = true;
return;
}
// obtain file size.
fseek (pFileIn , 0 , SEEK_END);
lSize = ftell (pFileIn);
rewind (pFileIn);

// allocate memory to contain the whole file.
char* buffer = (unsigned char*) malloc (lSize);
if (buffer == NULL)
{
Application->MessageBox("Za mało pamięci!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
fclose(pFileIn);
btnOpen2->Enabled = true;
return;
}

// copy the file into the buffer.
fread (buffer,1,lSize, pFileIn);

Crypt2(buffer, lSize, PASSWORD);

if(SaveDialog2->Execute())
{
FILE *pFileOut = fopen(SaveDialog2->FileName.c_str(), "wb"); //file will be overwritten
if(pFileOut)
{
fwrite(buffer, lSize, 1, pFileOut);
}
else
Application->MessageBox("Problem ze stworzeniem pliku końcowego!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
if(pFileOut) fclose (pFileOut);
}

if(pFileIn) fclose (pFileIn);
if(buffer) free (buffer);
}
btnOpen2->Enabled = true;
}
//---------------------------------------------------------------------------

//===========================================================================
// DEFINES and VARIABLES
//===========================================================================



void __fastcall TMain::btnOpen3Click(TObject *Sender)
{
btnOpen3->Enabled = false;
// CGauge2->Progress = 0;
if(OpenDialog2->Execute())
{
FILE *pFileIn = fopen(OpenDialog2->FileName.c_str(), "rb");
if(!pFileIn)
{
Application->MessageBox("Problem z otwieraniem pliku!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
btnOpen3->Enabled = true;
return;
}
// obtain file size.
fseek (pFileIn , 0 , SEEK_END);
lSize = ftell (pFileIn);
rewind (pFileIn);

// allocate memory to contain the whole file.
char* buffer = (unsigned char*) malloc (lSize);
if (buffer == NULL)
{
Application->MessageBox("Za mało pamięci!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
fclose(pFileIn);
btnOpen->Enabled = true;
return;
}

// copy the file into the buffer.
fread (buffer,1,lSize, pFileIn);

Crypt3(buffer, lSize, PASSWORD);

if(SaveDialog2->Execute())
{
FILE *pFileOut = fopen(SaveDialog2->FileName.c_str(), "wb"); //file will be overwritten
if(pFileOut)
{
fwrite(buffer, lSize, 1, pFileOut);
}
else
Application->MessageBox("Problem ze stworzeniem pliku końcowego!", Main->Caption.c_str(), MB_ICONEXCLAMATION);
if(pFileOut) fclose (pFileOut);
}

if(pFileIn) fclose (pFileIn);
if(buffer) free (buffer);
}
btnOpen3->Enabled = true;
}
//---------------------------------------------------------------------------

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

  void __fastcall SourceButtonClick(TObject *Sender)
{
  if( SourceOpenDialog->Execute() )
  {
  SourceEdit->Text = SourceOpenDialog->FileName;
  }
}

 

Undefined source open dialog. Problem przy łączeniu kodu. Coś z linkowaniem, jak to naprawić?

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

Dołącz do dyskusji

Możesz dodać zawartość już teraz a zarejestrować się później. Jeśli posiadasz już konto, zaloguj się aby dodać zawartość za jego pomocą.

Gość
Dodaj odpowiedź do tematu...

×   Wklejono zawartość z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Odnośnik został automatycznie osadzony.   Przywróć wyświetlanie jako odnośnik

×   Przywrócono poprzednią zawartość.   Wyczyść edytor

×   Nie możesz bezpośrednio wkleić grafiki. Dodaj lub załącz grafiki z adresu URL.

Ładowanie


×
×
  • Dodaj nową pozycję...