This forum is in archive mode. You will not be able to post new content.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Neea

Pages: [1] 2 3
1
Java / Re: Java quiz series
« on: November 18, 2013, 09:15:06 AM »
Your answer is correct, but if you need to compare the 2 values of the different objects, which was the case in my example you don't need to override the equals method, just use toString() and compare both as string objects. This was the reason why i let the toString() methods visible in my example. Please continue :)

2
Java / Re: Java quiz series
« on: November 16, 2013, 07:52:38 PM »
Say you have the following classes
Code: (java) [Select]

public abstract class Symbol {
private char symbol;
......... //constructor

@Override
public String toString() {
return new Character(symbol).toString();
}
}

public class Nonterminal extends Symbol {
        ........ //constructors

 @Override
public String toString() {
return super.toString();
}
}
public class Terminal extends Symbol {
        ..... //constructors

@Override
public String toString() {
return super.toString();
}
}


Will this compile or not, will it print out "it works" or not and why, and how would you make it work?


Code: (java) [Select]
......
Nonterminal nt = new Nonterminal("S");
Terminal st = new Terminal("S");

if(nt.equals(st)){
    System.out.println("It works");
}
.....


Not a particularly hard question, but oh well .... my java knowledge is fairly limited.

3
Creative Arts / Re: The Music Thread
« on: November 16, 2013, 05:41:10 PM »
Myrath - Sour Sigh


http://www.youtube.com/watch?v=oUaAwuGnCvo


Been stuck on this song for 5 days now :)
/thread necro

4
Java / Re: Java quiz series
« on: November 16, 2013, 09:13:39 AM »
It will not compile, because you cannot convert from double to int without data loss.
How would I fix it? Depends, if i want a floating point result, chance type of x to double, if i want an int result add cast to int and deal with data loss.

5
Java / Re: Java quiz series
« on: November 13, 2013, 10:30:14 AM »
Love the idea for the quiz :) Makes me want to learn java better.


Yes it compiles and the result is 1
You're basically mixing casts with operators ....
So you first have -1, then you cast it to long so it's gonna be long -1
Then you have + unary operation so it remains long -1, then you cast it to int => int -1
Then you have - operation => int 1, after cast to char => char 1
After + operation so it's gonna be char 1
Then cast to byte => byte 1
And in the end implicitly cast to int => int 1


Think that's about right.
I have no idea for the next challenge cuzz i don't know java that well :)

6
Java / Re: [Java] Lexical Scanner
« on: November 12, 2013, 06:10:37 AM »
+1 for the observations. Noted and will be taken into account. It is indeed ugly java code :P

7
Creative Arts / Re: Jacket
« on: November 12, 2013, 06:07:52 AM »
Very nice, i love how you managed to create such intense emotional states of mind, only from the color of a jacket. It felt borderline obsession, and you literally managed to transmit that feeling to the reader ... please continue =]

8
Java / [Java] Lexical Scanner
« on: November 01, 2013, 11:06:09 PM »
This is a lexical analyzer for a very reduced form of a language, composed by myself with all it's lexical rules and components. One fact worth mentioning is that I made my life easier by not performing look-ahead for operators of type ==,<=,>= etc, and also it does not have functions, classes etc. It parses a text file in which a basic program is written.


These are language related, you can figure out how my language looks like after them etc.
Code: (java) [Select]

//Adds operators to list
private void getOperators(){
operators.add("<"); operators.add(">");
operators.add("lt"); operators.add("gt");
operators.add("="); operators.add("equals");
operators.add("plus"); operators.add("minus");
}


//Adds reserved words to list
private void getReservedWords(){
reservedWords.add("if"); reservedWords.add("else"); reservedWords.add("while");
reservedWords.add("int"); reservedWords.add("char"); reservedWords.add("string");
reservedWords.add("main"); reservedWords.add("cin>>"); reservedWords.add("cout<<"); //really skipping that look ahead step here :D
}


//Adds separators to list
private void getSeparators(){
sepList.add("("); sepList.add(")"); sepList.add(",");
sepList.add(";"); sepList.add("["); sepList.add("]");
}


//Adds codification to list
private void getCodification(){
codification.add("identifier");
codification.add("constant");
codification.add("main");
codification.add("int");
codification.add("char");
codification.add("string");
codification.add("cout<<");
codification.add("cin>>");
codification.add("while");
codification.add("if");
codification.add("else");
codification.add(";");
codification.add(",");
codification.add("[");
codification.add("]");
codification.add("(");
codification.add(")");
codification.add("plus");
codification.add("minus");
codification.add("<");
codification.add(">");
codification.add("=");
codification.add("lt");
codification.add("gt");
codification.add("equals");
}


And now for the Scanner part, it basically parses lines, breaks it in tokens and then decides if token is reserved word, operator, separator, identifier, constant and it adds them to PIF/ST respectively; or error. The regex should tell you about the language constraints.
Code: (java) [Select]

//Bubble sort for SymbolTable type elements in a list, alphabetically after token
//Yes bubble sort.
        /* Note this was a particular requirement, it could have been done way more elegantly, but not when one is out of time. */
public void sortST(List<SymbolTable> list){


for(int i=0; i<list.size();i++){
for(int j=1; j<(list.size()-i);j++){
if(list.get(j-1).getToken().compareTo(list.get(j).getToken()) > 0 ){
SymbolTable aux = new SymbolTable(list.get(j-1).getToken(), list.get(j-1).getPosition());
SymbolTable aux1 = new SymbolTable(list.get(j).getToken(), list.get(j).getPosition());
list.set(j-1, aux1);
list.set(j, aux);
}
}
}
}


//Adds token in PIF or SymbolTable
public void classify(String token, Integer nr){
//System.out.println(token + "Here token");
int aux=0,index = 0, aux1=0, index1=0;
if(nr==0){
for(int i=0; i<codification.size(); i++){
if(codification.get(i).equals(token)){
Classification item = new Classification(i,nr);
pif.add(item);
break;
}
}
return;
}
if(nr==1){
if(symbolTableC.isEmpty()){
SymbolTable pair = new SymbolTable(token,1);
symbolTableC.add(pair);
}
for(int i =0; i< symbolTableC.size(); i++){
if(symbolTableC.get(i).getToken().equals(token)== true){
Classification item = new Classification(nr, symbolTableC.get(i).getPosition());
pif.add(item);
aux++;
break;
}
index=i;
}
if(aux==0){
int poz = symbolTableC.get(index).getPosition() +1;
SymbolTable pair = new SymbolTable(token, poz);
symbolTableC.add(pair);
Classification item = new Classification(nr, poz);
pif.add(item);
}
return;
}
if(nr == 2){
if(symbolTableI.isEmpty()){
SymbolTable pair = new SymbolTable(token,1);
symbolTableI.add(pair);
}
for(int i =0; i< symbolTableI.size(); i++){
if(symbolTableI.get(i).getToken().equals(token)== true){
Classification item = new Classification(0, symbolTableI.get(i).getPosition());
pif.add(item);
aux1++;
break;
}
index1=i;
}
if(aux1==0){
int poz = symbolTableI.get(index1).getPosition() +1;
SymbolTable pair = new SymbolTable(token, poz);
symbolTableI.add(pair);
Classification item = new Classification(0, poz);
pif.add(item);
}
return;
}


}


//Algorithm that determines if token is op/resW/sep/constant/identifier or error
public void scanAlg() throws Exception{
int counter = 0;
try{
BufferedReader br = new BufferedReader(new FileReader(this.file));
String line = new String();
Pattern constants = Pattern.compile("^-\\d+?|\\d+?|\\+\\d+?|'\\w'|\"\\w+?\"|\"\\s+?\"|''|' '$");
Pattern identifiers = Pattern.compile("^[a-zA-Z]+?|[a-zA-Z]\\d+?$");
Pattern costSpecial = Pattern.compile("^[1-9]\\d+?$");
String aux = "";
while((line = br.readLine())!= null){
counter++;
StringTokenizer tokenSplits = new StringTokenizer(line,"(),;=><[] ", true);
while(tokenSplits.hasMoreTokens()){

String token = tokenSplits.nextToken();
if(token.equals(" ")) continue;
if(reservedWords.contains(token) || sepList.contains(token) || operators.contains(token)){
classify(token, 0);
continue;
}
Matcher m = constants.matcher(token);
if(token.equals("-") | token.equals("+")){
aux = token;
continue;


}
Matcher s = costSpecial.matcher(token);
if(s.matches()){
String megaAux = aux.concat(token);
token = megaAux;
aux="";
}
if(m.matches()){
classify(token, 1);
continue;
}


Matcher t = identifiers.matcher(token);
int size = token.length();
if(t.matches() && size < 250){
classify(token,2);
continue;
}
throw new Exception("Error token: " + token + " on line " + counter);
}


}
br.close();
} catch (IOException e){
System.err.println(e.getMessage());
} catch (NumberFormatException e) {
System.err.println(e.getMessage());
} catch (NoSuchElementException e){
System.err.println(e.getMessage());
}
}


Any comments, suggestions, ways to improve the code etc. are welcome. (Well except for the bubble sort part  :P )

9
.NET Framework / Re: Belaso(Vigenere) Cipher
« on: November 01, 2013, 06:50:02 AM »
Not bad :) I really didn't think it that way +1 for the idea. Definitely improved the complexity :)

11
General discussion / Re: How Did You Get Started?
« on: October 15, 2013, 04:43:52 PM »
I'm currently in the incipient phase, mostly a cocoon.
But nonetheless a computer networks class and evilzone were the triggers of this interest in the subject. Of course we all were kids once that perhaps wished to become the greatest "black/white/gray" hat out there after watching some hacker related movie, i know i was :) But it always seemed like that far away childish dream, you know ... like going on the moon. And it is, but i believe that as long as the subject, or the dream, offers you passion and a will to go on, it is worth chasing until the end. No matter the outcome.


Programming related, my interests started in the 5th grade while watching my older sister writing a program in C on the blue screen of borland. God i fell in love with that eye hurting blue screen, and those yellowish pieces of code. After that i finished a computer science related high school, and here i am studying computer science in university. And hopefully evolving into that dream butterfly. (God that comparison seems so girly lol)

12
Found it on the Webs / Re: Offline P2P network Dead Drops
« on: October 04, 2013, 08:59:58 AM »
Am I the only one who thinks that this is like sex without protection? lol
Though the idea is pretty cool. +1

13
.NET Framework / Belaso(Vigenere) Cipher
« on: October 03, 2013, 09:35:29 PM »
The Belaso cipher is a classic cipher that uses as key a word and encrypts plain text by dividing it in blocks the size of the key, and adding to each position of the alphabet corresponding to the letter in the block , the position in the alphabet of the letter of the key that shares the same index(comparing the plaintext block and key text)


This was an exercise to get back into programming. It turned out a fun mix of windows forms, C# and C lol.


First variant: Using ASCII code. This one respects a 26 english letter alphabet, from A to Z.


Code: (cpp) [Select]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string plainTxt, key;
        StringBuilder encrText = new StringBuilder();
        StringBuilder decrText = new StringBuilder();
        public Form1()
        {
            InitializeComponent();
        }
        public String decryption()
        {
            plainTxt = plainText.Text.ToUpper();
            key = keyText.Text;
            int ksize = key.Length;
            int msize = plainTxt.Length;
            char[] txt = plainTxt.ToCharArray();


            for (int i = 0; i < msize; i++)
            {
                char decr = txt[i] - getShift(key, i) < 65 ? (char)((txt[i] - getShift(key, i)) + 27) : (char)((txt[i] - getShift(key, i)) - 1);
                decrText.Append(decr);
            }
            return decrText.ToString();
        }


        public String encryption()
        {
            plainTxt = plainText.Text.ToUpper();
            key = keyText.Text.ToUpper();
            int ksize = key.Length;
            int msize = plainTxt.Length;
            if (ksize > msize) { return "Key size must be smaller than plaintext size"; }
            char[] txt = plainTxt.ToCharArray();


            for (int i = 0; i < msize; i++)
            {
                char encr = txt[i] + getShift(key, i) > 90 ? (char)((txt[i]+ getShift(key,i))- 26) : (char)((txt[i] + getShift(key, i))+1);
                encrText.Append(encr);
            }
            return encrText.ToString();
        }
        private int getShift(string key, int i)
        {
            char[] k = key.ToCharArray();
            int temp = i%key.Length;
            return ((int)key[temp]) - 65;
        }


        private void encrButton_Click(object sender, EventArgs e)
        {
            String encrypted = encryption();
            resultBox.Clear();
            resultBox.AppendText(encrypted);
        }


        private void decrButton_Click(object sender, EventArgs e)
        {
            String decrypted = decryption();
            resultBox.Clear();
            resultBox.AppendText(decrypted);
        }
    }
}





Second variant: Using a predefined 27 char alphabet, including space. This was more fun to write since my C# knowledge is definitely not the best and there were issues that actually raised some 20mins and cig break to think about lol In the end my C knowledge beats my C# lol.


Code: (cpp) [Select]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace BelasoCipher2
{
    public partial class Form1 : Form
    {
        string alpha = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string plainTxt, cdkey;
        public Form1()
        {
            InitializeComponent();
        }
        //Return integer values to plaintext
        public String convertS(List<int> intCrypt)
        {
            int size = intCrypt.Count;
            StringBuilder rez= new StringBuilder();
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < 27; j++)
                {
                    if (intCrypt[i] == j) //if integer value = position add letter to string
                        rez.Append(alpha[j]);
                }
            }
            return rez.ToString();
        }


        //Modulo function for Z classes
        private int mod(int x, int m)
        {
            int r = x % m;
            return r < 0 ? r + m : r;
        }
        //Encryption/decryption algorithm based on integer values of alphabet/key/plaintext
        private string decriEncryAlg(int n){
            plainTxt = ptextBox.Text.ToUpper();
            cdkey = keyBox.Text.ToUpper();
            int size = plainTxt.Length;
            String result;
            List<int> kLi = new List<int>();
            List<int> pLi = new List<int>();
            List<int> resList = new List<int>();
            int klen = cdkey.Length;
            if (klen > size) { return "Key size must be smaller than plaintext size"; }
            kLi = keyCode(cdkey); // get integer position value in the alphabet of key
            pLi = divideString(plainTxt, klen); //get integer position value in the alphabet of plaintext
            int pLiSize = pLi.Count;
            int temp = 0;
            int index = 0;
            while (temp <= pLiSize) // going on chunks of key size up to integer value of plaintext list size
            {
                for (int i = 0; i < klen; i++)
                {
                    if (index >= pLiSize) //If index >= size then return the result of encr/decr
                    {
                        result = convertS(resList);


                        return result;
                    }
                    int tempAux;
                    if(n == 0) tempAux = pLi[index]+kLi[i]; //if 0 then encryption
                    else tempAux = pLi[index]-kLi[i]; //else decryption
                    resList.Add(mod(tempAux, 27));
                    index++;
                }
                temp += klen;
            }
            result = convertS(resList);


            return result;
        }


        public string decryption()
        {
            string result = decriEncryAlg(1);
            return result;
        }


        public string encryption()
        {
            string result = decriEncryAlg(0);
            return result;
         
        }
        //Get integer values according to alphabet of key word
        public List<int> keyCode(string key)
        {
            List<int> list = new List<int>();
            int len = key.Length;
            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < 27; j++)
                {
                    if (key[i].Equals(alpha[j])) list.Add(j);
                }
            }
            return list;               
        }
        //Divide plaintext in chunks <=the size of key word and get their integer value from the alphabet
        public List<int> divideString(string s, int k)
        {
            List<int> list = new List<int>();
            int size = plainTxt.Length;
            int temp = 0, ke=k;
            StringBuilder aux = new StringBuilder();
            do
            {
                for (int z = temp; z < ke; z++)
                {
                    if (z >= size) break;
                    aux.Append(plainTxt[z]);
                } 
                for (int i = temp; i < ke; i++)
                {
                    if (i >= size) return list;
                    for (int j = 0; j < 27; j++)
                    {
                        if (aux[i].Equals(alpha[j])) list.Add(j);
                    }
                }
                temp = temp + k;
                ke += ke;
            } while (temp <= size+k);
            return list;
        }


        private void encButton_Click(object sender, EventArgs e)
        {
            String encrypted = encryption();
            textBox3.Clear();
            textBox3.AppendText(encrypted);
        }


        private void decrButton_Click(object sender, EventArgs e)
        {
            String decrypted = decryption();
            textBox3.Clear();
            textBox3.AppendText(decrypted);
        }
    }
}



14




I practically grew up with this series of games, Heroes II being the first one I've played, and going up to Heroes VI (though couldn't imerse myself in it because my laptop was overheating)

Each game was definitely amazing in it's own way, but Heroes V has a special place in my heart.
When it first came out and I started playing it I hated it. I didn't like the graphics, and I had the unluck of starting a mission in underground, which is a bit harder to navigate. So I just said "This game sucks, I'll go back to Heroes IV", until I stayed at a friend of mine which was playing it, and made me fall in love with it.



Top Points for Heroes V:
-Highly interesting story line, with long campaigns for every race
-Two sets of skills (racial and regular)
-A big number of abilities, that can be customized depending on your hero's race (One I liked the most was the "Fallen Knight" where a Knight that took death magic became fallen)
-Awesome combat system and creature abilities, though the expansions increase that even more
-3D cartoonish graphics which has quite some hilarious moments
-A variety of new artifacts



Top Points for Heroes V Expansions (Hammers of Fate and Tribes of the East)
-Two new highly interesting factions, with some awesome combat abilities
-Return of the Heroes IV caravans (i thought without them the game was much harder in Heroes 5)
-Tribes of the East brings another set of evolved creatures to choose from
-Continuation of the story in Heroes V


Overall I found the game experience highly interesting, with a great story line and awesome creatures and incredibly cool spells. I think it's a game that turn-based strategy lovers should definitely give it a try.

15
General discussion / Re: Post your deskTOP
« on: August 26, 2013, 07:54:22 PM »
Reinstalled windows, new desktop. I think this one is better.

Pages: [1] 2 3


Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.