• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RC4 Algorithm in java Please Review

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is My algorithm is correct please review guys?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if your program correctly implements the RC4 algorithm.

However, there are issues with the coding style, which make your program very hard to read and understand.

Please indent your code properly, instead of starting every line at the leftmost column. Proper indentation makes it much easier to see the structure of the program.

Use meaningful variable names. You are using many one- or two-letter variable names that don't show the meaning of the variable. Also, in Java, the most commonly accepted coding style is that variable names start with a lower-case letter (and class names start with an upper-case letter).

Also, you are not using static correctly, mixing static and non-static member variables. It looks like you only made the member cipher static because you got an error "non-static member cannot be accessed from a static context" when you tried to use cipher from the main method. Study Understanding Class Members to understand what static means and when you should or should not use it.

Also, you are doing all the work in the constructor of the class RC4algo. That's not good OO design. Constructors should only be used to initialize the state of an object, not to do the majority of the work that a class needs to do.
 
Marshal
Posts: 79403
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:. . . an error "non-static member cannot be accessed from a static context" . . .

Do you think that would be less frequent a problem if the error message said something like,

Instance member xyz can only be accessed from an instance context

?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell probably yes, then we would maybe see the opposite problem - people trying to remove the static keyword from the main method and then wondering why their program doesn't run.
 
Campbell Ritchie
Marshal
Posts: 79403
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:. . . we would maybe see the opposite problem . . .

 
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic