الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج تشفير zigzag بالجافا .ممكن المساعده

بدأه the heart white في 14 مايو 2012 · 7 رد · 1,144 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
/// <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

*قمت ببعض التعديل واصبح عندي خطائين لااعرف ماالسبب

تم تعديل هذه المشاركة بواسطة the heart white في 14 مايو 2012 في 21:07

#2

ما الأخطاء التي تواجهها بالضبط؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3
//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;}

في تعريف c

والخطا موجود بهذا الجزء

#4

اخي للوهله الاولي من قراتي لبرنامجك يبدو كانه مكتوب بسي شارب فلا ادري اذا تم اضافة foreach في جافا 7 ولكني في جافا 6 لايوجد شيئ من هذا القبيل

كما ان String في جافا هو اوبجكت وليس built in type كما في سي شارب string

حتى استخدامك لنمط الملاحظات xml comments يدل على انه من السي شارب

لقد قمت بعمل اكثر من كلاس باسم ZigZagCipher كما ان الاستيراد به خطا فالصحيح هو java.util.* ولكنك نسيت حرف الi وكتبته java.utl.*

ابدا بهذه التصحيحات ثم سوف نرى مالمتبقي

بالمناسبة : انا عضو كاي عضو اخر ، ورجاء لاتخص بالذكر اي شخص على انه العضو المميز او غيره، فربما اساعدك في سؤال بينما هناك اخرون يستطيعون الاجابه عن اسئلة لا استطيع ان اساعدك فيها

تحياتي

3

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#5
اقتباس

بالمناسبة : انا عضو كاي عضو اخر ، ورجاء لاتخص بالذكر اي شخص على انه العضو المميز او غيره، فربما اساعدك في سؤال بينما هناك اخرون يستطيعون الاجابه عن اسئلة لا استطيع ان اساعدك فيها

+1 :)


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#6
اقتباس

فلا ادري اذا تم اضافة foreach في جافا 7 ولكني في جافا 6 لايوجد شيئ من هذا القبيل

foreach موجودة من جافا 5

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#7
علاء الصالحي كتب:

foreach موجودة من جافا 5

تحياتي

السلام عليكم استاذ علاء ، بالنسبة لforeach فانا لا اقصد

 for (i : arr)

وانما foreach كkey word وهذا ما يوجد في السي شارب ، اذا كان هناك foreach في جافا فهذا شيئ جديد بالنسبة لي ولم يسبق لي التعامل معه

ومن خبرتكم نستفيد إن شاء الله

تحياتي

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#8

اه فهمت عليك الآن

صحيح كلامك

ولم يتم إضافتها في سبعة أجريت تجربة للتأكد من الموضوع

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…