/// <summary>
/// method for demonstrating the ZigZag Cipher
/// (Also known as the Rail Fence Cipher)
/// </summary>
/// <param name="str">string we wish to apply the cipher to</param>
/// <returns>the ciphered string</returns>
import java.utl.*;
public class ZigZagCipher
{
public static void main(String args[])
{
//create zip & zag (we're only using
//2 rails so this represents top and bottom rails)
string zig = "";
string zag = "";
//convert the input string to a char array
char[] chrArray = str.ToCharArray();
//this lets us know if we're dealing with the
//top or bottom rail
bool isTopRow = true;
//loop through the char array
for ( c in chrArray)
{
//if we're dealing with the top rail add
//current char to zig
if (isTopRow == true)
zig += c.ToString();
else
//otherwise add to zag
zag += c.ToString();
//change status
isTopRow = !isTopRow;
};
//concantenate the 2 and return
return zig + zag;
}
/// <summary>
/// method for undoing the zigzag cipher
/// </summary>
/// <param name="str">the string we're working with</param>
/// <returns>the converted string</returns>
public static string DecipherZigZag(string str)
{
//create zig & zag which both hold 1/2 the original string
string zig = str.Substring(0, str.Length / 2);
string zag = str.Substring(str.Length / 2);
//top & bottom counter to hold our position
int top = 0;
int bottom = 0;
//hold the deciphered string
string decyphered = "";
bool isTopRow = true;
//loop through the string, making sure we havent gone too far
while (decyphered.Length != str.Length)
{
//if we're dealing with the top rail then add to
//deciphered from the zig char array
if (isTopRow == true)
{
decyphered += zig.Substring(top, 1);
top++;
}
else
{
//otherwise add from the zag char array
decyphered += zag.Substring(bottom, 1);
bottom++;
}
isTopRow = !isTopRow;
}
return decyphered;
}
}//convert the input string to a char array
char[] chrArray = str.ToCharArray();
//this lets us know if we're dealing with the
//top or bottom rail
bool isTopRow = true;
//loop through the char array
foreach (char c in chrArray)
{
//if we're dealing with the top rail add
//current char to zig
if (isTopRow == true)
zig += c.ToString();
else
//otherwise add to zag
zag += c.ToString();
//change status
isTopRow = !isTopRow;
}
//concantenate the 2 and return
return zig + zag;
}/// <summary>
/// method for demonstrating the ZigZag Cipher
/// (Also known as the Rail Fence Cipher)
/// </summary>
/// <param name="str">string we wish to apply the cipher to</param>
/// <returns>the ciphered string</returns>
import java.utl.*;
public class ZigZagCipher
{
public static void main(String args[])
{
//create zip & zag (we're only using
//2 rails so this represents top and bottom rails)
string zig = "";
string zag = "";
//convert the input string to a char array
char[] chrArray = str.ToCharArray();
//this lets us know if we're dealing with the
//top or bottom rail
bool isTopRow = true;
//loop through the char array
foreach (char c in chrArray)
{
//if we're dealing with the top rail add
//current char to zig
if (isTopRow == true)
zig += c.ToString();
else
//otherwise add to zag
zag += c.ToString();
//change status
isTopRow = !isTopRow;
}
//concantenate the 2 and return
return zig + zag;
}
/// <summary>
/// method for undoing the zigzag cipher
/// </summary>
/// <param name="str">the string we're working with</param>
/// <returns>the converted string</returns>
public static string DecipherZigZag(string str)
{
//create zig & zag which both hold 1/2 the original string
string zig = str.Substring(0, str.Length / 2);
string zag = str.Substring(str.Length / 2);
//top & bottom counter to hold our position
int top = 0;
int bottom = 0;
//hold the deciphered string
string decyphered = "";
bool isTopRow = true;
//loop through the string, making sure we havent gone too far
while (decyphered.Length != str.Length)
{
//if we're dealing with the top rail then add to
//deciphered from the zig char array
if (isTopRow == true)
{
decyphered += zig.Substring(top, 1);
top++;
}
else
{
//otherwise add from the zag char array
decyphered += zag.Substring(bottom, 1);
bottom++;
}
isTopRow = !isTopRow;
}
return decyphered;
}
}السلام عليكم ورحمه الله وبركاته
اسعد الله مساكم ,,
كيف الحال ؟؟ انا قد كتبت موضوع لبرنامج تشفير ولكن للاسف خطا ومارضي يشتغل معي واشكر كل من حاول مساعدتي
وبالاخص mental-driller فهو نبراس هذا المنتدى .
وبعد البحث ووجدت هذا الكود ولما شغلته طلع فيه 22 خطا وعدلته وبعد التعديل صار فيه 4 اخطاء ماعرفتها اتمنى تساعدوني فيه للضروره
وجزاء الله خير كل من حاول وساعدني في هذا البرنامج.
والخطا الي طلع عندي بعد التشغيل هو موجود بالكود لحاله ماعرف المشكله بالتعريف او loop
*قمت ببعض التعديل واصبح عندي خطائين لااعرف ماالسبب



