暗号ソフトのソースコード公開
僕が以前作った暗号ソフトのソースコードの一部を公開してみますね。 これで全部じゃないけど、だいたいこんな感じに暗号処理をしています。 分かる人は分かるかもしれないけど、このプログラムで暗号化しても、暗号の専門家にかかれば30分ぐらいで、復号化できてしまいます。 でも、素人にはそんなことはできないだろうから、ま、とりあえず、いっか、と思っています。 暗号ソフトのソースコード(一部抜粋) ↓↓↓ #define FK_RAND_MAX 32768 static unsigned long next = 1; void CAngokunDlg::OnOK() { // 代金支払いチェック CString strPro; strPro = theApp.GetProfileString("ang123123","angentry1231234","no"); if(strPro != "ang20") { int nPro; nPro = theApp.GetProfileInt("ang123123","angentry123123",0); if(nPro == 0) { theApp.WriteProfileInt("ang123123","angentry123123",1); } else { if(nPro > 9) { MessageBox("ご利用回数が10回を超えました。"); MessageBox("シェアウエア代金を支払い、パスワードを入力して下さい"); return ; } else { nPro++; theApp.WriteProfileInt("ang123123","angentry123123",nPro); } } } else { m_Button3.ShowWindow(SW_HIDE); } // 暗号化 CFile infile; CFile outfile; CString str1,str2,str3; m_Edit1.GetWindowText(str1); if(!infile.Open(str1,CFile::modeRead)) { MessageBox("暗号元ファイルが存在しない、もしくはファイル名が異常です。"); m_Edit1.SetFocus(); return ; } m_Edit2.GetWindowText(str2); unsigned long lKey; char buff[128]; memcpy(buff,str2.GetBuffer(128),sizeof(buff)); int j; lKey = 0; for(j=0; j < str2.GetLength(); j++) { lKey += (unsigned long)buff[j]; } fk_srand(lKey); m_Edit3.GetWindowText(str3); if(!outfile.Open(str3,CFile::modeCreate | CFile::modeWrite)) { MessageBox("暗号化ファイル名が入力されてない、もしくはファイル名が異常です。"); m_Edit3.SetFocus(); infile.Close(); return ; } char buff1[1024+1], buff2[1024+1]; int len; int i; // ファイルのバージョン情報設定 memcpy(buff2,"ango0100",8); try { outfile.Write(buff2,8); } catch(CFileException* ) { MessageBox("ファイルの書き込み異常"); infile.Close(); outfile.Close(); return ; } while(-1) { try { len = infile.Read(buff1,1024); } catch(CFileException* ) { MessageBox("ファイルの読み込み異常"); infile.Close(); outfile.Close(); return ; } for(i=0; i<len; i++) { angoka(buff1[i],&buff2[i],fk_rand()); } try { outfile.Write(buff2,len); } catch(CFileException* ) { MessageBox("ファイルの書き込み異常"); infile.Close(); outfile.Close(); return ; } if(len < 1024) { break; } } infile.Close(); outfile.Close(); MessageBox("暗号化正常終了しました。"); // CDialog::OnOK(); } void CAngokunDlg::angoka(char ch1, char *ch2, unsigned long lKey) { // nKey分シフト int nSift; unsigned int c; unsigned char uch2; nSift = lKey % 8; if(nSift == 0) { nSift = 1; } uch2 = (unsigned char)ch1; c = uch2; c = c | (uch2 * 0x01000000); c = _rotl(c, nSift); uch2 = c; *ch2 = uch2; } unsigned long fk_rand(void) { next = next * 1103515245 + 12345; return (next/65536) % RAND_MAX; } void fk_srand(unsigned long seed) { next = seed; }