This question already has answers here:
Sharing R functionality with multiple users without exposing code [closed]
(2 answers)
Closed 8 years ago.
I am new to R.
Suppose I have an R code which takes certain real time inputs and gives output in real time.
I want to share it with a third party which uses C++ in such a way that the logic of my code is not seen but he will get output with the input he provides.
So here there are two things.
1: He uses C++ to give input
2: I have to somehow integrate my R code with his data in such a way that he can get only the output, not my logic
so my objective is two fold. One is integration with C++ and second is code protection.
How can this be done?
Simple: just write a server process that accepts incoming data via TCP and sends the responses back. Run this on a separate machine, because otherwise the client will be able to gain access to your code.
Related
This question already has answers here:
Evaluating arithmetic expressions from string in C++ [duplicate]
(7 answers)
Closed 7 years ago.
i wonder if is possible, for example read a file with some content like:
a+b*c
and that my programm "create" a function to do this operation, and if i modify the file ( like a+b*c+2 ) the programm read this changes and updates what this function do. Well i dont have a solid backbround in the basis of C++ and i don't know if what i'm asking is just plain stupid. I need ( or something like this could be nice ) for my work in physics simulations, where the model is mainly definied by a equilibrium function ( and some other parameters ) so what i think is that could be good if i can make a programm to test this models without having to writte a special code for each one...
Thanks!
C++ is not interpreted code. So you can only compile hard coded expressions in source code. However you can evaluate an expression on your own. You can look at some solutions here
for sure it is "possible", actually that's what matlab, mapple or any other formal calculation software/lib do.
BTW, writing one may be quite simple if you just handle */+- basic operators, and may become more and more complex depending on what you want to use (sin cos, exp, log etc.)
Basic implementations reads of the input and build an internal tree with final values on leaves would look like soething like this in your case:
+
a *
b c
I'm sure you can find a lot of docs on it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I realize this isn't an ideal question, but i'll do my best to explain it :)
Firstly, the scenario is that I have been tasked for creating a simulation of a building with multiple elevators.
Let's assume my building consists of between 2 and 5 elevators, and an arbitary number of floors. The goal here was to allow "People" to board the elevators and travel to different floors.
The key point here is running each of the elevators concurrently.
I have managed to do this in C++ with a Thread for each elevator. What I am struggling to do is think of a simple way to do this with Message Passing in Erlang. I am not asking for a code answer, but moreso, an explanation of how i could approach this problem using message passing. I have of course attempted to read information on the topic, but it's confusing me.
I understand thus far that the threads must communicate via passing Messages to each other. Any help clarifying an approach on this is greatly appreciated. This is not graded homework or anything, and is an exercise for my knowledge.
Final Question:
How can I model a building with multiple elevators programmed to operate independently using Message Passing (in Erlang).
Instead of maintaining a shared state, you give each process its own state, and if anything changes you send messages with the update (and associated data) to all relevant processes
What Daniel is calling a process is an Erlang process, not a thread. They might seem like threads, but they are at least as different as they are similar... So it's really best to call them processes.
You need to be careful not to carry with you a C mind set when you come to design Erlang solutions. The point of Erlang is that it's a different paradigm, and whilst Erlang itself is implemented in C and thus everything you do in Erlang is ultimately run in a C thread, it's important to largely forget that and work with the Erlang paradigm instead.
In C are something to be managed, they are tricky and bite you when you aren't keeping a careful watch on them. Erlang processes are wonderful, you can to all intents and purposes spawn an unlimited number of them, and they don't really require any looking after as such.
In your lift scenario, as Daniel said, spawning a process for each lift is a reasonable design. One of the things to consider with Erlang is that numnbers in cases like this don't really matter, once you write a module to model your lift, you can spawn 2 to 5 of them, or 2 to 5 million of them, and you usually find with Erlang that it makes very little difference.
I'm not saying you can't design a broken implementation, but honestly, once you get used to Erlang you'll find it really lends itself to rapid development without the usual parallel and concurrency pitfalls.
As you progress your lift scenario, the right way to take it forwards is to get to know OTP, use something like a gen_server for your lifts, and a supervisor to spawn them dynanmically (or not) from it. If your lift crashes the process will then automatically get replaced/restarted. This is analagous to a lift breaking down (process has died; lift is unavailable) and the repair engineer coming and fixing it (process restarted; lift is available again). What happens to any people in the lift when it breaks down is perhaps a more advanced topic, for which there are a few possible solutions.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to provide a binary-only program written in C or C++ where the user has to pass a valid code via command line to be able to use some extra features of the program itself. The idea is to implement some verification strategy in the program which compares the passed code against a run-time generated code which univocally identifies the system or hardware on which the program is being run.
In other words, if and only if the run-time check:
f(<sysinfo>) == <given code>
is true, then the user is allowed to use the extra features of the program. f is the function generating the code at run-time and sysinfo is an appropriate information identifying the current system/hardware (i.e. MAC address of the first ethernet card, Serial Number of the processor, etc..).
The aim is to make it as much difficult as possible for the user to guess or (guess the way to calculate) a valid code without knowing f and sysinfo a priori. More importantly, I want it to be difficult to re-implement f by analyzing the disassembled code of the program.
Assuming the above is a strong strategy, how could I implement f in C or C++ and what can I choose as its argument? Also what GCC compiler flags could I turn on to obfuscate f specifically? Note that, for example, things like MD5(MAC) or MD5(SHA(MAC)) would be too simple for evident reasons.
EDIT: Another interesting point is how to make it difficult for the user to attack the code directly by removing or bypassing the portion of the code doing the check.
If you are on Windows, a standard strategy is to hash the value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid
If you're worried that a user might "guess" the hash function, take a standard SHA256 implementation and do something sneaky like change the algorithm initialization values (one of the two groups of these uses binary representations of the cube roots of the primes to initialize - change it to 5th or 7th or whatever roots, starting at the nth place, such that you chop off the "all-zero" parts, etc.)
But really if someone is going to take the time to RE your code, it's much easier to attack the branch in the code that does the if (codeValid) { allowExtraFeatures(); } then to mess with the hashes... so don't worry too much about it.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there any kind of “expression class” (C++)
I want to make a class that holds a function that is defined at run time.
i.e.
function function1("x*sin(3.141*x)");
I want to do things like find roots and it would be better not having to rewrite the program each time.
edit: I am looking at lua.
This thing is certainly much easier in dynamic languages. For example, in Matlab you can evaluate strings using the eval command.
However, this is not impossible in C++. You might be able to make a nice solution with a combination of C++11 lambdas and a custom interpreter. The member function can take a lambda as an argument, and you can formulate the lambda by interpreting a string.
This answer might give you a good starting point for the interpreting part of the challenge.
Evaluate Mathematical Function from String
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 months ago.
Improve this question
Currently I'm working on a C/C++ cross-platform client/server software. I'm very experienced developer when it comes to low level socket development.
The problem with Berkley sockets/Winsock, is that you always have to make some kind of parser to get things right on the receiver side. I mean, you have to interpret data, and concatenate packets in order to transmit correctly. (packets often get sliced)
Have in mind that the communication is going to be bidirectional. Is pure socket the best way to transmit data nowadays? Would you recommend SOAP, Webservices or another kind of encapsulation to this application?
I can highly recommend Google Protocol Buffers.
These days many people use Web Services and SOAP. There are C++ packages available for this purpose. These will use sockets for you and handle all the data wrangling. If you are on Unix/Linux, give or take System V.4 network handles, your data will eventually travel over sockets.
On Windows there are other choices if you only want to talk to other Windows boxes.
You could also look into CORBA, but it's not the common practice.
In any data transfer, there is going to be a need to serialize and deserialize the objects.
The first question you want to ask is whether you want a binary or text format for the transfer. Binary data formats have the distinct advantage that they are totally easy to parse (provided they are simple POD structures - you can just cast them into a struct).
Text based transfers should be easier to debug since you can just read the text. You are still going to have to parse them.
SOAP based web services are simple XML based packets sent normally over HTTP. Something will have to parse the HTTP and the XML. The ease of use is not intrinsic but rather dependent of the tools at your disposal. If you have good tools, the by all means, but the same applies to any form of data exchange.
You can take a look at the Boost Serialization Library. It is a fairly complex library and does require you to write code indicating what members need to be serialized. IT does have good support for both text (including xml) and binary serialization. It is also cross platform.
I have used ZMQ with grate success. I highly recommend it as it is a middle-level library witch takes care the socket related overhead. It also supports binary packets/messages.