0x69 41 Junior Poster

Additional idea how to see similarity between Vigenère and XOR ciphers is this- compare encryption formulas-

Vigenère cipher => C = (P+K) mod 26 XOR cipher => Cb = (Pb+Kb) mod 2 Here C/P/K is ciphertext/plaintext/key letters respectivelly and Cb/Pb/Kb is ciphertext/plaintext/key bits respectivelly.

So the only differences are:
1. Vigenère performs modulo 26 arithmetic and XOR performs modulo 2 arithmetic.
2. Vigenère encryption is letter-by-letter and XOR encryption is bit-by-bit.

So as you can see from the formulas both ciphers make substitution in plaintext data. And hence both ciphers are called substitution ciphers, which have little or no security.

BTW, if ciphers uses random key which size equals to size of plaintext, then both ciphers becomes One-time_pad which is unbreakable even in theory !!!

Good luck !

0x69 41 Junior Poster

A VERY interesting question ! Thanks for asking such thing :)

Both methods are polyalphabetic ciphers. There are some algorithms for polyalphabetic ciphers which computes key size from ciphertext. Once key size is known, ciphertext can be splitted into columns which are vulnerable to simple frequency analysis.
So answer is that both methods have the same level of security.
http://www.security-forums.com/viewtopic.php?t=15961

0x69 41 Junior Poster

I made some fixes, here corrected version:

#include<stdio.h>
#include <stdlib.h>

void getOption();
void getData(int *num1, int *num2);
void calc(int option, int num1, int num2);
float add(int num1, int num2);
float sub(int num1, int num2);
float mul(int num1, int num2);
float divm(int num1, int num2);
void printResult(float result);

void clrscr() {
	// define what is clrscr() - legal on Win
	system("cls");
}

void getch() {
	// getch is non-standard C and should be avoided.
	// use ANSI-C compliant getchar function
	getchar();
}

int main()
{

clrscr();
getOption();
getch();
}

void getOption()
{
// initialize num1,num2 to something
// otherwise you will get runtime error
int option,num1=0,num2=0;

clrscr();
printf("[1] Addition\n");
printf("[2] Subtraction\n");
printf("[3] Multiplication\n");
printf("[4] Division\n");
printf("\nChoose options: ");
scanf("%d", &option);
calc(option,num1,num2);

}

void getData(int *num1, int *num2)
{
printf("Enter two integers: ");
scanf("%d %d", num1, num2);
}

void calc(int option, int num1, int num2)
{
switch(option)
{
case 1: clrscr();
printf("\"ADDITION\"\n");
getData(&num1,&num2);
printResult(add(num1,num2));
break;

case 2: clrscr();
printf("\"SUBTRACTION\"\n");
getData(&num1,&num2);
printResult(sub(num1,num2));
break;

case 3: clrscr();
printf("\"MULTIPLICATION\"\n");
getData(&num1,&num2);
printResult(mul(num1,num2));
break;

case 4: clrscr();
printf("\"DIVISION\"\n");
getData(&num1,&num2);
printResult(divm(num1,num2));
break;

default: printf("Invalid key");

}
// put pause, before repeating user actions
system("pause");
main();
}

float add(int num1, int num2)
{
int add;

add=num1+num2;
return add;
}

float sub(int num1, int num2)
{
int sub;

sub=num1-num2;
return sub;
}

float mul(int num1, int num2)
{
int mul;

mul=num1*num2;
return mul;
}

float divm(int num1, int num2)
{
float div;

div=num1/num2;
return div;
}

void printResult(float result)
{
printf("The result is: %.2f\n", result);
getch();
}
0x69 41 Junior Poster

Well, right now i'm using linux, but i've heard that windows is really best for programing videogames ( on c++ ) well, wich O.S. do you think is the best?

P.D. Sorry for the bad english jeje :$

When it comes to game development definitely answer is Windows. Simply because nothing beats it at tools available for game & graphics development. For example,- take a look at existing programs for Pixel Shader development & testing under Linux/Mac/Windows:
http://en.wikipedia.org/wiki/GLSL#IDE
From these nothing beats feature-rich and bug-free program "Render Monkey" which currently is only for Windows.
This is just one example, but in principle same should hold for many other development tools for graphics-driven applications.
If you want second example take a look at NVIDIA solution which lets developing programs for GPU (through OpenCL,CUDA,...) DIRECTLY in Visual Studio ->
http://developer.nvidia.com/object/nsight.html
So we can say that now Windows has IDE for GPU development. Do Linux has GOOD alternatives to this ?

0x69 41 Junior Poster

Wouldn't it be simpler to do like this ?

#define TYPE extern type
// then in code it would be 
type x = initfunction()
// or
TYPE x = initfunction()

Both look more or less the same AND you will know that if type declaration is done with macro - it will be extern.

0x69 41 Junior Poster

Error is straightforward - where you declared 'example' variable ?

0x69 41 Junior Poster

It is best not write additional while loop, but instead on required condition - exit for loop. Something like that:

for(i = 0; i < N; i++)
	{
		printf("Please enter: number name surname midterm final hw1 hw2\n");
		scanf( "%d %s %s %d %d %d %d", 
			  &info[i].number, 
			  info[i].name, 
			  info[i].surname, 
			  &info[i].midterm, 
			  &info[i].final, 
			  &info[i].hw1, 
			  &info[i].hw2);
		// terminate input of students on some condition
		if (info[i].number==-1) {
			break;
		}
	}

Nothing happens after you enter -1, possibly because scanf function waits for other parameters for input. You should enter WHOLE line to terminate loop,- something like=> -1 1 1 1 1 1 1

0x69 41 Junior Poster

What's more, i can not print the information by this command:

printf ( "%d %s %s %d %d %d %d", &info[i].number, info[i].name, info[i].surname, &info[i].midterm, &info[i].final, &info[i].hw1, &info[i].hw2   );

Where may the problem be?

printf expects parameters, not addresses to them,- so remove '&' from arguments to printf.

0x69 41 Junior Poster

Well... then you can read line by line as string and parse that line with strtok(), something like:

scanf("%s", current_line);
  char * pch = strtok (current_line, " ");
  while (pch != NULL)
  {
    sscanf(pch,"%d", &current_K);
    pch = strtok (NULL, " ");
  }
0x69 41 Junior Poster

you can try something with loop, kind of:

scanf("%d", &k);
for (int i=0; i<k; i++) {
  printf(" ");
  scanf("%d", &k_number);
}
0x69 41 Junior Poster

In my opinion I at first tried to implement new ball speed as superposition of ball speed and paddle speed. In vector form it would be:

V_ball_new = V_ball + V_paddle

Results should be interesting too.

Good luck.

0x69 41 Junior Poster

Its called every time a walk-button or attack-button is pushed on the keyboard, its just 2 lines of code, something like this:

switch(Key) {

for(unsigned i = 0; i < Monsters.size(); i++)
if(Collision(Monsters.at(i), Player1) == true)
Player1->Collision[Player1->GetDirection()] = true;

//handle keys here etc.
}

As I understood Monsters.size() is monster count in whole map. If it is so - it is very inefficient code. I would do instead something like that:

#define CELL_WIDTH 40
#define CELL_HEIGHT 40
#define M SCREEN_WIDTH/CELL_WIDTH
#define N SCREEN_HEIGHT/CELL_HEIGHT
List* map_grid[M][N];
// in player and monster movement code add this
map_grid[object.grid_row][object.grid_col]->remove(objIndex) // clear wherever object was before
object.grid_row = object.positionX/CELL_WIDTH;
object.grid_col  = object.positionY/CELL_HEIGHT; 
map_grid[object.grid_row][object.grid_col]->append(monster.Index) // aka. your monster index i
/* now after button press 
instead of for(unsigned i = 0; i < Monsters.size(); i++)
do this
*/
for(int i = Player.grid_row-K; i<Player.grid_row+K; i++) {
  for(int j = Player.grid_col-K; j<Player.grid_col+K; j++) {
    for(/*iterate through all monsters at map_grid[i][j]*/) { 
      if(Collision(Monsters.at(currentMonster), Player);
      // ... do what you like here
    }
  }
}
// only think How to set constant K. It can be some small number.
// Or you can program it to be related to maximum possible monster size in terms of grid cell count.

That is. Definitely after implementing this, your program should run faster, because instead of looping through ALL monsters you will loop only through nearest cells (nearest monsters) around player. That's a big difference in perfomance. Also carefully choose container of monsters at cell. It can be that LIST dynamic insertions/removal will compensate …

0x69 41 Junior Poster

You mean the CHARACTER class code?

No, I mean code which executes Collision() function.

0x69 41 Junior Poster

It's more interesting to me How you pass objects for collision detection routine ? I'm asking because routine for choosing which objects to pass into

int Collision(CHARACTER* object1, CHARACTER* object2)

this function also very important for perfomance issues. It can be that it is more important than collision detection itself.
Can you put that routine code here?

0x69 41 Junior Poster

Ok, well the code is doing exactly what i want it to do except for one minor thing. It is always returning 1. I'm thinking there is something wrong with the for loop when I am comparing bday and bday[j].


#include <stdlib.h>
#include <time.h>
int party(int g);
main()
{
// bla bla bla
      int party(int g)
{
      int i, j, bdays[g];
      long int parties;
       for(i = 0; i < g; i++)
       {
             bdays[i] = 1 + rand() % 365;
       // why you iterating util guestCount here ?
      // it doesn't make sense here, because
      // rest bdays with j > i will be empty.
     // Besides this will repair your error when you
    // was comparing guest birthday with himself (i==j)
    // so =>
       for (j = 0; j < i  /*g*/; j++)
       {
          if (bdays[i] == bdays[j])
             return 1;
             else
                 i - 1;
             if (i == 0)
                return 0;
       }
       }
}

Also there are some nonsensical code here - what is this ?

else
   i - 1;

??
But i dont like brute-force search as I said before, because it will perform slow. So you should try to search for duplicates as in my example before OR at least:
1. Sort bdays array with QSORT function.
2. Then search that bdays array in acending order with only one loop, something like

// sort bdays
qsort(bdays,...);
// search for duplicates
// (this only do AFTER you generate ALL guest birthdays)
for (j …
0x69 41 Junior Poster

All I need to do now is make a loop to check if two+ guests have the same bday and have it return 1 or 0.

I optimized a bit calculation of duplicates - main idea is that when guest count is less than 365 -> we should iterate through guests and not through year days. In that case we win some CPU cycles. Theoretically speed-up factor would be 365/guestCount. If you simulate 1,000,000 parties then this is important thing :)
Code:

int HasDuplicates(int bornedThisDay[], int bdays[], int guestCount ) {
	int byGuests = (guestCount < 365);
	int until = (byGuests)? guestCount:365;
	int skipThisDay[365];
	int duplicates = 0;
	
	for (int i=0; i < until; i++) {
		if (byGuests) {
			if (!skipThisDay[bdays[i]]) {
				duplicates = bornedThisDay[bdays[i]];
				skipThisDay[bdays[i]] = 1;
			}
		}
		else {
			duplicates = bornedThisDay[i];
		}
		if (duplicates > 1)
			break;
	}
	return (duplicates > 1);
}

int bornedThisDay[365] -> this is aka. duplicates[] array as in Adak example.

Good luck !