Return to Unfiction unforum
 a.r.g.b.b 
FAQ FAQ   Search Search 
 
Welcome!
New users, PLEASE read these forum guidelines. New posters, SEARCH before posting and read these rules before posting your killer new campaign. New players may also wish to peruse the ARG Player Tutorial.

All users must abide by the Terms of Service.
Website Restoration Project
This archiving project is a collaboration between Unfiction and Sean Stacey (SpaceBass), Brian Enigma (BrianEnigma), and Laura E. Hall (lehall) with
the Center for Immersive Arts.
Announcements
This is a static snapshot of the
Unfiction forums, as of
July 23, 2017.
This site is intended as an archive to chronicle the history of Alternate Reality Games.
 
The time now is Mon Nov 11, 2024 10:15 pm
All times are UTC - 4 (DST in action)
View posts in this forum since last visit
View unanswered posts in this forum
Calendar
 Forum index » Meta » Various & Sundry
Need help debugging this code
Moderators: Giskard, imbri, ndemeter
View previous topicView next topic
Page 1 of 1 [2 Posts]  
Author Message
Hamled
Greenhorn

Joined: 08 Mar 2003
Posts: 7
Location: North Carolina

Need help debugging this code

I realize this isn't really related to ARGs (thats why it's in this forum, I guess), but I've been having a little trouble getting my code (written in C++, for MFC) for an encryption/decryption program to work as well as I'd like...
I'm already on version 2.5 from the bugs I've found and fixed, but there are some others that I can't get....
Of particular note is a problem when decrypting a previously encrypted string... The first letter of the string isn't decrypted back correctly, although all others are. The problem is a bit more complicated than this, but I'd have to explain how the entire program works, for one to fully understand. I'm going to post the most relevant code here, and attach the entire file (the one with the actual encryption/decryption code in it), to this post, and also the zipped entire source, with a compiled version of the program with it.

Code:

void CCrypter1Dlg::OnEncrypt()
{
   UpdateData(TRUE);
   m_strOutput = _T("");
   int      InputLength = m_strInput.GetLength();
   int    CurCharacter = 0;
   int      OverloadBuffer = 0;
   int      Modifier = 0;
   bool   isUpper=false;
   int      NumAlpha=GetAlphaCharacters(m_strInput);\
   int      CurNum=1;

   //Encrypt First Character
   CurCharacter=m_strInput.GetAt(0);
   isUpper=GetCase(CurCharacter);
   CurCharacter=toupper(CurCharacter);
   if(CurCharacter >= 'A' && CurCharacter <= 'Z')
   {
      if(m_bOnlyAlpha)
         CurCharacter=CurCharacter+NumAlpha;
      else
         CurCharacter=CurCharacter+InputLength;
      if(CurCharacter > 'Z')
         CurCharacter=KeepInBounds(CurCharacter);
   }
   CurCharacter=ReturnCase(CurCharacter, isUpper);
   m_strOutput += CurCharacter;
   
   //Do The Rest
   for(int i=1; i<InputLength;i++)
   {
      CurCharacter=m_strInput.GetAt(i);
      isUpper=GetCase(CurCharacter);
      CurCharacter=toupper(CurCharacter);
      if(CurCharacter >= 'A' && CurCharacter <= 'Z')
      {
         Modifier = GetModifier(m_strOutput, i);
         if(CurNum%2)
         {
            CurCharacter=CurCharacter+Modifier;
            CurCharacter=KeepInBounds(CurCharacter);
         }
         else
         {
            CurCharacter=CurCharacter-Modifier;
            CurCharacter=KeepInBounds(CurCharacter);
         }
         CurNum++;
      }
      CurCharacter=ReturnCase(CurCharacter, isUpper);
      m_strOutput += CurCharacter;
   }
   UpdateData(FALSE);

}

void CCrypter1Dlg::OnDecrypt()
{
   UpdateData(TRUE);
   m_strOutput = _T("");
   int      InputLength = m_strInput.GetLength();
   int      CurCharacter = 0;
   int      OverloadBuffer = 0;
   int      Modifier = 0;
   bool   isUpper=false;
   int      NumAlpha=GetAlphaCharacters(m_strInput);
   int      CurNum=1;

   //Encrypt First Character
   CurCharacter=m_strInput.GetAt(0);
   isUpper=GetCase(CurCharacter);
   CurCharacter=toupper(CurCharacter);
   if(CurCharacter >= 'A' && CurCharacter <= 'Z')
   {
      if(m_bOnlyAlpha)
         CurCharacter=CurCharacter-NumAlpha;
      else
         CurCharacter=CurCharacter-InputLength;
      if(CurCharacter < 'A')
         CurCharacter=KeepInBounds(CurCharacter);
   }
   CurCharacter=ReturnCase(CurCharacter, isUpper);
   m_strOutput += CurCharacter;

   //Do The Rest

   for(int i=1; i<InputLength;i++)
   {
      CurCharacter=m_strInput.GetAt(i);
      isUpper=GetCase(CurCharacter);
      CurCharacter=toupper(CurCharacter);
      if(CurCharacter >= 'A' && CurCharacter <= 'Z')
      {
         Modifier = GetModifier(m_strInput, i);
         if(CurNum%2)
         {
            CurCharacter=CurCharacter-Modifier;
            CurCharacter=KeepInBounds(CurCharacter);
         }
         else
         {
            CurCharacter=CurCharacter+Modifier;
            CurCharacter=KeepInBounds(CurCharacter);
         }
         CurNum++;
      }
      CurCharacter=ReturnCase(CurCharacter, isUpper);
      m_strOutput += CurCharacter;
   }
   
   UpdateData(FALSE);
}

crypter 1dlg.cpp
Description 
cpp

 Download 
Filename  crypter 1dlg.cpp 
Filesize  6.51KB 
Downloaded  116 Time(s) 
crypter1.zip
Description 
zip

 Download 
Filename  crypter1.zip 
Filesize  33.01KB 
Downloaded  140 Time(s) 

PostPosted: Tue Mar 25, 2003 7:46 pm
 View user's profile AIM Address MSN Messenger
 ICQ Number 
 Back to top 
Hamled
Greenhorn

Joined: 08 Mar 2003
Posts: 7
Location: North Carolina

Well... I fixed it, sorta... now the whole decryption is wrong, but the first character is fine! Razz

PostPosted: Tue Mar 25, 2003 8:23 pm
 View user's profile AIM Address MSN Messenger
 ICQ Number 
 Back to top 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
View previous topicView next topic
 Forum index » Meta » Various & Sundry
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
You cannot post calendar events in this forum



Powered by phpBB © 2001, 2005 phpBB Group