Atbash

Jun 16, 2014 at 6:01pm
Please, help me with the following two errors, I cant't understand what happens:

1st)

Error 2 error LNK2019: unresolved external symbol "char * __cdecl descifrar(char *,char *,char *)" (?descifrar@@YAPADPAD00@Z) referenced in function _main


2nd)

Error 3 fatal error LNK1120: 1 unresolved externals



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
char* cifrar(char*, char*, char*);
char* descifrar(char*, char*, char*);

void main()
{
	char alfabeto[] = {"abcdefghijklmnopqrstuvwxyz"};//26
	char numeros[]  = {"0123456789"};//10
	char frase[256];

	cout<<"**CIFRADO ATBASH**"<<endl;
	cout<<endl;
	cout<<"Frase: ";
	gets(frase);
	cout<<endl;

	//Medir lo que ha escrito el usuario.
	int longitud  = 0;
	longitud = strlen(frase);
	//Crear dos vectores dinámicos
	//1) Vector que guarda la frase cifrada.
		char *frasecifrada = new char[longitud];
	//2) Vector que guarda la frase descifrada.
		char *frasedescifrada = new char[longitud];
	
	//Usar la función para cifrar la frase
	frasecifrada = cifrar(frase,alfabeto,numeros);
	frasedescifrada = descifrar(frase,alfabeto,numeros);
	
	//Mostrar por pantalla los resultados
	cout<<"La frase cifrada es: "<<frasecifrada<<endl;
	//cout<<"La frase descifrada es: "<<frasedescifrada<<endl;

	//liberar memoria
	delete []frasecifrada;
	//delete []frasedescifrada;
}

char* cifrar(char* frase, char* alfabeto, char* numeros)
{
	//Medir la longitud de la frase a transformar
	int longitud = 0;
	longitud = strlen(frase);

	//Poner 0 donde no haya frase
	for (int i = longitud; i<256; i++)
	{
		frase[i] = 0;
	}

	//Empezar a cambiar letra a letra
	int pos = 0;
	int tipo =0;
	while(1)
	{
		int suport = 0;
		for (int i = 0; i<26 ; i++)
		{
			if (frase[pos] == alfabeto[i])
			{
				tipo = 1;
				suport = i;
				break;
			}
		}
		for (int i = 0; i<10; i++)
		{
			if(frase[pos] == numeros[i])
			{
				tipo = 2;
				suport = i;
				break;
			}
		}

		if (tipo == 1)
		{
			frase[pos] = alfabeto[suport];
		}
		else if (tipo == 2)
		{
			frase[pos] = numeros[suport];
		}
		pos++;
	}
	char *vsol = new char[longitud];
	for (int i = 0;i<longitud;i++)
	{
		vsol[i] = frase[i];
	}
	return(vsol);
}

//char* descifrar(char* frasecifrada, char* alfabeto, char* numeros)
//{
//
//} 
Jun 16, 2014 at 6:05pm
You are trying to use descifrar function on line 31, but it is not defined anywhere.
Jun 16, 2014 at 7:39pm
Thanks "MiiNiPaa", now I've chanched some things, but it doesn't work, does somebody knows why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
char* cifrar(char*, char*, char*);
char* descifrar(char*, char*, char*);

void main()
{
	char alfabeto[] = {"abcdefghijklmnopqrstuvwxyz"};//26
	char numeros[]  = {"0123456789"};//10
	char frase[256];

	cout<<"**CIFRADO ATBASH**"<<endl;
	cout<<endl;
	cout<<"Frase: ";
	gets(frase);
	cout<<endl;

	//Medir lo que ha escrito el usuario.
	int longitud  = 0;
	longitud = strlen(frase);
	//Crear dos vectores dinámicos
	//1) Vector que guarda la frase cifrada.
		char *frasecifrada = new char[longitud];
	//2) Vector que guarda la frase descifrada.
	//	char *frasedescifrada = new char[longitud];
	
	//Usar la función para cifrar la frase
	frasecifrada = cifrar(frase,alfabeto,numeros);
	//frasedescifrada = descifrar(frase,alfabeto,numeros);
	
	//Mostrar por pantalla los resultados
	cout<<"La frase cifrada es: ";
	for (int i = 0; i < longitud ; i++)
	{
		frasecifrada[i];
	}
	//cout<<"La frase descifrada es: "<<frasedescifrada<<endl;

	//liberar memoria
	delete []frasecifrada;
	//delete []frasedescifrada;
}

char* cifrar(char* frase, char* alfabeto, char* numeros)
{
	//Medir la longitud de la frase a transformar
	int longitud = 0;
	longitud = strlen(frase);

	//Empezar a cambiar letra a letra
	int pos = 0;

	while(1)
	{	
		int tipo =0;
		int suport = 0;
		for (int i = 0; i<26 ; i++)
		{
			if (frase[pos] == alfabeto[i])
			{
				tipo = 1;
				suport = i;
				break;
			}
		}
		for (int i = 0; i<10; i++)
		{
			if(frase[pos] == numeros[i])
			{
				tipo = 2;
				suport = i;
				break;
			}
		}

		if (tipo == 1)
		{
			frase[pos] = alfabeto[26-suport];
		}
		else if (tipo == 2)
		{
			frase[pos] = numeros[10-suport];
		}
		
		if (longitud == pos)
		{
			break;
		}
		pos++;
	}
	return(frase);
}

//char* descifrar(char* frasecifrada, char* alfabeto, char* numeros)
//{
//
//} 
Jun 16, 2014 at 7:54pm
What I instantly see is that main should have signature int main()

Be more descriptive. What exactly does not work?
Jun 16, 2014 at 8:49pm
it's true, but out teacher sais that we have to pute void I don't know why...

The problem is that at the time of execution, the program asks for a sentence, and then appears the mesage "The pass phrase is:" and then gives an error that closes the program.
Jun 16, 2014 at 10:37pm
Ok, I've solved the problem, but now I need help to delete properly the dynamic vector.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
char* cifrar(char*, char*, char*);
char* descifrar(char*, char*, char*);

void main()
{
	char alfabeto[] = {"abcdefghijklmnopqrstuvwxyz"};//26
	char numeros[]  = {"0123456789"};//10
	char frase[256];

	cout<<"**CIFRADO ATBASH**"<<endl;
	cout<<endl;
	cout<<"Frase: ";
	gets(frase);
	cout<<endl;

	//Medir lo que ha escrito el usuario.
	int longitud  = 0;
	longitud = strlen(frase);
	//Crear dos vectores dinámicos
	//1) Vector que guarda la frase cifrada.
		char *frasecifrada = new char[longitud];
	//2) Vector que guarda la frase descifrada.
		char *frasedescifrada = new char[longitud];
	
	//Usar la función para cifrar la frase
	frasecifrada = cifrar(frase,alfabeto,numeros);
	
	//Mostrar por pantalla los resultados
	cout<<"La frase cifrada es: ";
	for (int i = 0; i < longitud ; i++)
	{
		cout<<frasecifrada[i];
	}
	cout<<endl;
	cout<<endl;
	frasedescifrada = descifrar(frase,alfabeto,numeros);
	cout<<"La frase descifrada es: ";
	for (int i = 0; i < longitud ; i++)
	{
		cout<<frasedescifrada[i];
	}

	cout<<endl;
	cout<<endl;

	//liberar memoria
	//delete []frasecifrada;
	//delete []frasedescifrada;
}

char* cifrar(char* frase, char* alfabeto, char* numeros)
{
	//Medir la longitud de la frase a transformar
	int longitud = 0;
	longitud = strlen(frase);

	//Empezar a cambiar letra a letra
	int pos = 0;

	while(1)
	{	
		int tipo =0;
		int suport = 0;
		for (int i = 0; i<26 ; i++)
		{
			if (frase[pos] == alfabeto[i])
			{
				tipo = 1;
				suport = i;
				break;
			}
		}
		for (int i = 0; i<10; i++)
		{
			if(frase[pos] == numeros[i])
			{
				tipo = 2;
				suport = i;
				break;
			}
		}

		if (tipo == 1)
		{
			frase[pos] = alfabeto[26-suport-1];
		}
		else if (tipo == 2)
		{
			frase[pos] = numeros[10-suport-1];
		}
		
		if (longitud == pos)
		{
			break;
		}
		pos++;
	}
	return(frase);
}

char* descifrar(char* frasecifrada, char* alfabeto, char* numeros)
{
	//Medir la longitud de la frase a transformar
	int longitud = 0;
	longitud = strlen(frasecifrada);

	//Empezar a cambiar letra a letra
	int pos = 0;

	while(1)
	{	
		int tipo =0;
		int suport = 0;
		for (int i = 0; i<26 ; i++)
		{
			if (frasecifrada[pos] == alfabeto[i])
			{
				tipo = 1;
				suport = i;
				break;
			}
		}
		for (int i = 0; i<10; i++)
		{
			if(frasecifrada[pos] == numeros[i])
			{
				tipo = 2;
				suport = i;
				break;
			}
		}

		if (tipo == 1)
		{
			frasecifrada[pos] = alfabeto[26-suport-1];
		}
		else if (tipo == 2)
		{
			frasecifrada[pos] = numeros[10-suport-1];
		}
		
		if (longitud == pos)
		{
			break;
		}
		pos++;
	}
	return(frasecifrada);
}
Jun 17, 2014 at 10:05pm
can somebody answer the question please?
Jun 17, 2014 at 11:21pm
At the end of main():
1
2
delete[] frasecifrada;
delete[] frasedescifrada;
Jun 18, 2014 at 7:33am
No, 'frasecifrada' is pointing to 'frase' that was not dynamic allocated.
1
2
3
4
5
	//1) Vector que guarda la frase cifrada.
		char *frasecifrada = new char[longitud];
	
	//Usar la función para cifrar la frase
	frasecifrada = cifrar(frase,alfabeto,numeros); //memory leak 
same for 'frasedescifrada'


you didn't need to use new.
Topic archived. No new replies allowed.