![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Be Free
|
Code...
Here's A Place To Post Your Code. I Would Like To See Some Of The Creative Things You Can Come Up With Through Your Programming. But Hold On, We Need A Format... Ok, So
<language> <special programs to run it> <purpose/reason> <code> //please use the [code] tags to make it nead! Now Let's Get Out there And Program!
__________________
Suicide Command in Linux : rm -rf / ;) AIM:TheLoneWolf071@aim.com--If You Need Help, Don't Hesitate... |
|
|
|
|
|
#3 (permalink) |
|
Be Free
|
Code:
/*
Created By DarkRedRose( @)--}--- )
Created On November 05, 2005
Created For:Searching Documents, Just Enter The Document Name And
This Will Locate It And Tell You Where.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h> //use if in linux
#include <math.h>
#define s_buffer 80
char *flush(char *);
/*
fgets leaves a pesky \n at the end of ever string to know when it's finished
so we make a function to get rid of it, hence the flush
*/
int main(int argc, char *argv[])
{
char
string_to_lookfor[s_buffer],
string_searching[s_buffer],
filename[s_buffer],
temp_string[s_buffer];
long unsigned int
search_number=0,
for_i,
for_j, //special variables for the for loop
for_k;
FILE *search_file;
printf("What File Would You Like To Search?\n:"); //Asks Filename
fgets(filename, s_buffer, stdin); //Takes filename
if(strlen(filename) == 0 || strcmp(filename, "\n") == 0)
{
printf("Woops! You Forgot To Enter A Value, Quiting Now!\n");
exit(0);
}
strcpy(filename, flush(filename));
search_file = fopen(filename, "r"); //opens the filename and assigns the stream to the searchfile pointer
if(search_file == NULL)
{
perror(search_file);
/*
prints reason error, compiler will give you flack about it not
being a pointer, don't worry about that
*/
exit(0); //quits if it doesn't exist
}
printf("\nWhat String Would You Like To Search For?\n:");
fgets(string_to_lookfor, s_buffer, stdin);
if(strlen(string_to_lookfor) == 0 || strcmp(string_to_lookfor, "\n") == 0)
{
printf("Woops! You Forgot To Enter A Value, Quiting Now!\n");
exit(0);
}
strcpy(string_to_lookfor, flush(string_to_lookfor)); //takes off the end \n
search_number = strlen(string_to_lookfor); //number of char's in the string
for(for_i=0; !feof(search_file); for_i++)
{
fgets(string_searching, s_buffer, search_file);
if(strlen(string_searching) == 0 || strcmp(string_searching, "\n") == 0)
{
continue;
}
strcpy(string_searching, flush(string_searching));
for(for_j = 0; for_j < strlen(string_searching); for_j++)
{
for(for_k = 0; for_k < search_number; for_k++)
{
temp_string[for_k] = string_searching[for_k+for_j];
}
temp_string[for_k] = '\0';
/*
Ok, So temp_string likes to tag on ugly letters at the end,
so we need this go get rid of it
*/
if((strcmp(string_to_lookfor, temp_string)) == 0)
{
printf("Match Found For %s! It's On Line:%lu At Character:%lu\n",string_to_lookfor, for_i+1, for_j+1);
}
}
}
fclose(search_file);
return 0;
}
char *flush(char *string_flush)
{
if(string_flush[strlen(string_flush) - 1] == '\n')
{
string_flush[strlen(string_flush) - 1] = '\0'; //last char will be \0
}
return string_flush;
}
|
|
|
|
|
|
#4 (permalink) |
|
Registered User
|
I liked your idea and heres what I came up with for it:
Usage: Code:
tgo@localhost:~/c$ cat test askdfkl asdfasdf BOB dsf BOB JOE TIM BOB tgo@localhost:~/c$ gcc -o search search.c tgo@localhost:~/c$ ./search Usage: search <file> <text> tgo@localhost:~/c$ ./search test BOB Match found at line: 3 Match found at line: 5 Match found at line: 8 tgo@localhost:~/c$ Code:
#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
{
FILE *file;
char cur[80];
int x;
x = 1;
if (argc != 3)
{
printf("Usage: search <file> <text>\n");
exit(1);
}
if ((file = fopen(argv[1],"r")) == NULL)
{
printf("Error opening file.\n");
exit(1);
}
while (fgets(cur, 80, file))
{
if(strstr(cur,argv[2]))
{
printf("Match found at line: %d\n",x);
}
x++;
}
return 0;
}
__________________
My new homepage: |
|
|
|
|
|
#5 (permalink) |
|
Be Free
|
Very Nice... Here's A New One, It's Short And Sweet, But Find The Factors Of any number, upto 2^32...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
unsigned long int
for_i,
for_j,
factor_input;
if(argc!=2)
{
printf("Usage: %s <Number To Factor>\n", argv[0]);
exit(0);
}
for(for_j=0; for_j < strlen(argv[1]); for_j++)
{
if(isdigit(argv[1][for_j]) == 0)
{
printf("You Must Enter A Number!\n");
exit(0);
}
}
factor_input=atoi(argv[1]);
if(factor_input > 2147483647)
{
printf("AHHHH, Number's To Big\n");
exit(0);
}
printf("The Factors of %lu Are :\n\n", factor_input);
for(for_i = 1; for_i < factor_input+1; for_i++)
{
if(factor_input%for_i == 0)
{
printf("%lu\n", for_i);
}
}
printf("\n");
return 0;
}
__________________
Suicide Command in Linux : rm -rf / ;) AIM:TheLoneWolf071@aim.com--If You Need Help, Don't Hesitate... |
|
|
|
|
|
#7 (permalink) |
|
TSF Enthusiast
Join Date: Dec 2004
Posts: 604
OS: windows xp
|
//language: C++
//Random number generator. Will generate as many numbers as needed between min value enter and max value enter including min and max. Code:
#include<iostream>
#include <ctime>
#include<cstdlib>
using namespace std;
int main()
{
int max;
int min;
int rolls;
int roll;
int count;
char z='y';
while(z=='y')
{
cout<<"enter number of rolls"<<endl<<endl;
cin>>rolls;
srand(time(0));
cout<<"enter min roll"<<endl<<endl;
cin>>min;
cout<<"enter max roll"<<endl<<endl;
cin>>max;
cout<<endl<<endl;
max=max-min+1;
count=1;
while(rolls>0)
{
roll=(rand() % max) + min;
cout<<"roll number "<<count<<": "<<roll<<endl;
roll=0;
rolls--;
count++;
}
cout<<endl<<endl<<"do you want to roll again(type y or n)"<<endl;
cin>>z;
}
return 1;
}
__________________
|
|
|
|
|
|
#9 (permalink) | |
|
TSF Enthusiast
Join Date: Dec 2004
Posts: 604
OS: windows xp
|
Quote:
__________________
|
|
|
|
|
|
|
#10 (permalink) |
|
Registered User
|
Here is some linux assembly that takes in two numbers and gives you the output. Not very cool but was playing with C functions in assembly.
Useage: Code:
tgo@localhost:~/asm$ nasm -f elf add.asm tgo@localhost:~/asm$ gcc -o add add.o tgo@localhost:~/asm$ ./add Enter two numbers 25 30 Total of 25 and 30 is 55 tgo@localhost:~/asm$ Code:
[SECTION .text] extern printf extern scanf global main main: ; show input banner push dword entermsg call printf add esp,4 ; get first number with scanf push dword one push dword num call scanf add esp,8 ; get second number with scanf push dword two push dword num call scanf add esp,8 ; add numbers and store in eax mov eax,[one] add eax,[two] ; show total push values for totalmsg to display push eax push dword [two] push dword [one] push totalmsg call printf add esp,16 [SECTION .bss] one resd 1 two resd 1 [SECTION .data] entermsg db 'Enter two numbers',10,0 totalmsg db 'Total of %d and %d is %d',10,0 num db '%d',0
__________________
My new homepage: |
|
|
|
|
|
#11 (permalink) |
|
Registered User
|
I was in some random irc channel and they had a bot spit out the latest forum threads so I decided to code my own and then after it was done I thought it would be cool to make one for active forum users and here is the code.
Usage: Code:
<tgo> !users <Forums> Currently Logged in Users: john, Niels, tgo <tgo> !forum <Forums> Latest Forum Post: Forums irc bot -> http://www.anomalous-security.org/forum/viewtopic.php?t=1261 Code:
#!/usr/bin/perl -w
# Bot that reads the last forum post coded by Niels and tgo
# http://www.anomalous-security.org
use IO::Socket;
$server = "snake.zq1.de";
$nick = "Forums";
$ircport = 6667;
$httpport = 80;
$channel = "#aso";
Start();
sub Start {
$CONNECTION = IO::Socket::INET->new (
PeerAddr => $server,
PeerPort => $ircport,
Proto => 'tcp'
) or die;
print $CONNECTION "USER $nick 0 0 :$nick\n";
print $CONNECTION "NICK $nick\n";
print $CONNECTION "JOIN $channel\n";
while (my $input = <$CONNECTION>) {
if ($input =~ /:tgo!tgo\@je.to.jne/)
{
if ($input =~ /:!forum/)
{
getpage("/","rss_feeds2");
lastpost();
}
elsif ($input =~ /:!users/)
{
getpage("/forum/index.php","Registered Users:");
getuser();
}
}
print $CONNECTION "PONG $1\n" if $input =~ /PING (.*)/;
}
}
sub getpage {
my ($page,$keyword) = @_;
print "page is $page\n";
print "keyword is $keyword\n";
$CON = IO::Socket::INET->new (
PeerAddr => $server,
PeerPort => $httpport,
Proto => 'tcp'
) or die;
$request = "GET $page HTTP/1.1\r\n";
$request .= "Host: www.anomalous-security.org\r\n";
$request .= "User-Agent: Forums Bot\r\n";
$request .= "Connection: close\r\n\r\n";
print $CON $request;
while (my $text = <$CON>)
{
$all .= $text;
if ($text =~ /$keyword/)
{
$spot = length($all);
$s = $spot - length($text);
}
if ($text =~ /This data is based/)
{
$end = ($s - length($all)) * -1;
}
}
}
sub lastpost {
$chunk = substr($all,$spot+94,100);
$chunk =~ /(.*)">(.*)<\/a\>/;
print $CONNECTION "PRIVMSG $channel :Latest Forum Post: $2 -> http://www.anomalous-security.org/$1\n";
close($CON);
}
sub getuser {
$chunk = substr($all,$s,$end);
if ($chunk =~ /Registered Users: None/)
{
$names = "None";
}
else
{
$chunk =~ s/<([^>]*)>//g;
$chunk =~ /Registered Users: (.*)\s+/;
$names = $1;
}
print $CONNECTION "PRIVMSG $channel :Currently Logged in Users: $names\n";
}
__________________
My new homepage: |
|
|
|
|
|
#12 (permalink) |
|
Registered User
|
Code to break Caesars Box encrpytion.
Useage: Code:
tgo@localhost:~/perl$ perl cryp.pl HOUIY\!TO\! HITOYOU!! tgo@localhost:~/perl$ perl cryp.pl hoacfucdoowkach\?wdocwku?mwohoccluoduookacuccduwwhlhkclolwduihdo\! howmuchwoodwouldawoodchuckchuckifawoodchuckcouldchuckwood??lawl! tgo@localhost:~/perl$ For the important part the outer loop loops from 0 to the perfect square. The inner loop goes through the string and grabs inner * perfect square + outer loop. So for instance if we had an easy one like abcdefghi and it just started the loops it would grab 0 * 3 + 0 and take that character which would be a. then it would grab 0 * 3 + 1 which would be d then 0 * 3 + 2 which would be g. and that would be the first row. Code: Code:
#!/usr/bin/perl
# Code to break Caesars Box encryption
# Coded by tgo
# http://www.anomalous-security.org
use warnings;
if (@ARGV != 1)
{
warn("Useage $0 <string>\n");
exit(1);
}
$string = $ARGV[0];
$length = length($string);
for ($x=1;$x<20;$x++)
{
$total = $x * $x;
if ($total == $length)
{
$num = $x;
last;
}
elsif ($total >= $length)
{
warn("The length of your string is a not a perfect square\n");
exit(1);
}
}
for ($y=0;$y<$num;$y++)
{
for($in=0;$in<$length-$num;$in++)
{
$spot = $in*$num+$y;
if ($spot > $length)
{
last;
}
if ($in == 0)
{
$curline = substr($string,$spot,1);
}
else
{
$curline .= substr($string,$spot,1);
}
}
print $curline;
}
print "\n";
__________________
My new homepage: |
|
|
|
|
|
#13 (permalink) |
|
Be Free
|
Just For All Of You... Post you Code On redrose.homelinux.com via SSH Or FTP. If You Use FTP, login is
User:ftp Pass:<blank> -- FTP will not work with your browser... SSH is User:anon1 pass:anonymous if you use ssh, compile you code please... if FTP, i'll move your code to anon1 and compile it for you... P.S., also Post your Code Here...
__________________
Suicide Command in Linux : rm -rf / ;) AIM:TheLoneWolf071@aim.com--If You Need Help, Don't Hesitate... |
|
|
|
|
|
#14 (permalink) |
|
Be Free
|
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fin, *fout;
char *alpha="abcdefghigjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:\n/\\";
int input, for_i;
if(argc != 3)
{
printf("Usage: %s <Input Filename> <Output Filename>\n", argv[0]);
exit(0);
}
fin = fopen(argv[1], "rb");
fout = fopen(argv[2], "wb");
if(fin == NULL)
{
printf("Error:");
perror(fin);
exit(0);
}
if(fout == NULL)
{
printf("Error:");
perror(fout);
exit(0);
}
while(!feof(fin))
{
input = fgetc(fin);
for(for_i = 0; for_i < strlen(alpha); for_i++)
{
if(input == alpha[for_i])
{
fputc(input, fout);
}
}
}
return 0;
}
__________________
Suicide Command in Linux : rm -rf / ;) AIM:TheLoneWolf071@aim.com--If You Need Help, Don't Hesitate... |
|
|
|
|
|
#15 (permalink) |
|
Analyst, Security Team
Join Date: Nov 2005
Location: UK
Posts: 1,917
OS: xp
|
// Delphi
// selects 6 random numbers 1-49 LotteryNumbers.jpg Code:
// author: Moralterror
// date: 16/03/05
// selects 6 random numbers between 1-49
var num: array of integer;
var i: integer;
begin
setLength(num,6);
num[0] := random(49)+1;
label1.caption := '';
label2.caption := '';
label3.caption := '';
label4.caption := '';
label5.caption := '';
label6.caption := '';
label1.caption := IntToStr(num[0]);
repeat
num[1] := random(49)+1;
if num[1] <> num[0] then
begin
label2.caption := IntToStr(num[1]);
end;
until label2.caption > '';
repeat
num[2] := random(49)+1;
if num[1] <> num[2] then
begin
if num[2] <> num[0] then
begin
label3.caption := IntToStr(num[2]);
end;
end;
until label3.caption > '';
repeat
num[3] := random(49)+1;
if num[1] <> num[3] then
begin
if num[3] <> num[0] then
begin
if num[3] <> num[2] then
begin
label4.caption := IntToStr(num[3]);
end;
end;
end;
until label4.caption > '';
repeat
num[4] := random(49)+1;
if num[1] <> num[4] then
begin
if num[4] <> num[0] then
begin
if num[4] <> num[2] then
begin
if num[4] <> num[3] then
begin
label5.caption := IntToStr(num[4]);
end;
end;
end;
end;
until label5.caption > '';
repeat
num[5] := random(49)+1;
if num[1] <> num[5] then
begin
if num[5] <> num[0] then
begin
if num[5] <> num[2] then
begin
if num[5] <> num[3] then
begin
if num[5] <> num[4] then
begin
label6.caption := IntToStr(num[5]);
end;
end;
end;
end;
end;
until label6.caption > '';
end;
|
|
|
|
|
|
#16 (permalink) |
|
Registered User
Join Date: Dec 2005
Posts: 5
OS: XP
|
Lang: c++
Desc: Simple download client. The URL, server IP, and output file name is hardcoded - easy enough to change that, though. Code:
#include <windows.h>
#include <winsock2.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
cout << "Error at WSAStartup()\n";
system("PAUSE");
return 1;
}
// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET )
{
cout << "Error at socket(): " << WSAGetLastError();
WSACleanup();
system ("PAUSE");
return 1;
}
// Connect to a server.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "207.44.154.68" ); // Remote server IP
clientService.sin_port = htons( 80 );
if ( connect( m_socket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR)
{
cout << "Failed to connect.\n";
WSACleanup();
system("PAUSE");
return 1;
}
// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[] = "GET http://files4.rarlab.com/rar/wrar351.exe\n"; // 'GET' request
char recvbuf[512] = "";
long int total = 0;
// Send the request.
bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
cout << "Bytes Sent: " << bytesSent << endl;
HANDLE hFile;
DWORD dwBytesWritten;
// Open a file handle.
hFile = CreateFile(TEXT("Winrar.exe"), // file to create
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_ALWAYS, // overwrite existing
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
bool recving = true;
do
{
if (!(bytesRecv == 0) ||
(bytesRecv == SOCKET_ERROR && WSAGetLastError()== WSAECONNRESET) )
{
bytesRecv = recv( m_socket, recvbuf, 512, 0 ); // Receive data
if ( bytesRecv == -1 )
{
cout << "\nConnection Closed." << endl;
recving = false;
}
if ( bytesRecv != 0 )
{
recvbuf[bytesRecv] = '\0'; // NULL terminate recvbuf
// Output last received data chunk to file.
WriteFile(hFile, // handle to the file
recvbuf, // buffer containing the data to be written
bytesRecv, // number of bytes to be written
&dwBytesWritten, // pointer to variable that receives the number of bytes written
NULL); // no OVERLAPPED struct
total += bytesRecv;
system("CLS");
cout << "rev: " << total << " Bytes";
}
}
else
{
cout << "\n\nDone!\n";
cout << "\nTotal Bytes recv: " << total << endl;
CloseHandle(hFile);
recving = false;
}
} while (recving);
system("PAUSE");
return 0;
}
For Dev-C++ link to: libWS2_32.a Last edited by Cache : 02-16-2006 at 04:46 AM. |
|
|
|
|
|
#17 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 8
OS: XP
|
Can any of you programmers help me? i want to get something to add to a video clip to automatically delete it after its been watched once.
Kind of like a secret agent thing. I would be very greatful if you could help me out or tell me where i can download such a thing... |
|
|
|